home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / fscheck / RCS / checkdir.c,v < prev    next >
Encoding:
Text File  |  1990-11-02  |  101.5 KB  |  4,531 lines

  1. head     1.30;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.30
  10. date     90.11.01.23.28.33;  author jhh;  state Exp;
  11. branches ;
  12. next     1.29;
  13.  
  14. 1.29
  15. date     90.10.10.15.29.03;  author mendel;  state Exp;
  16. branches ;
  17. next     1.28;
  18.  
  19. 1.28
  20. date     90.10.10.11.22.10;  author jhh;  state Exp;
  21. branches ;
  22. next     1.27;
  23.  
  24. 1.27
  25. date     90.05.01.15.36.42;  author jhh;  state Exp;
  26. branches ;
  27. next     1.26;
  28.  
  29. 1.26
  30. date     90.02.14.15.55.27;  author jhh;  state Exp;
  31. branches ;
  32. next     1.25;
  33.  
  34. 1.25
  35. date     89.09.25.16.41.11;  author jhh;  state Exp;
  36. branches ;
  37. next     1.24;
  38.  
  39. 1.24
  40. date     89.08.29.17.28.15;  author jhh;  state Exp;
  41. branches ;
  42. next     1.23;
  43.  
  44. 1.23
  45. date     89.08.20.19.15.28;  author jhh;  state Exp;
  46. branches ;
  47. next     1.22;
  48.  
  49. 1.22
  50. date     89.06.22.17.50.37;  author jhh;  state Exp;
  51. branches ;
  52. next     1.21;
  53.  
  54. 1.21
  55. date     89.06.21.23.55.59;  author jhh;  state Exp;
  56. branches ;
  57. next     1.20;
  58.  
  59. 1.20
  60. date     89.02.28.12.22.19;  author jhh;  state Exp;
  61. branches ;
  62. next     1.19;
  63.  
  64. 1.19
  65. date     88.12.05.14.33.50;  author douglis;  state Exp;
  66. branches ;
  67. next     1.18;
  68.  
  69. 1.18
  70. date     88.09.20.15.14.07;  author nelson;  state Exp;
  71. branches ;
  72. next     1.17;
  73.  
  74. 1.17
  75. date     88.07.19.11.47.29;  author douglis;  state Exp;
  76. branches ;
  77. next     1.16;
  78.  
  79. 1.16
  80. date     88.06.02.12.59.45;  author brent;  state Exp;
  81. branches ;
  82. next     1.15;
  83.  
  84. 1.15
  85. date     87.11.13.13.04.36;  author nelson;  state Exp;
  86. branches ;
  87. next     1.14;
  88.  
  89. 1.14
  90. date     87.10.21.11.03.56;  author nelson;  state Exp;
  91. branches ;
  92. next     1.13;
  93.  
  94. 1.13
  95. date     87.10.21.10.38.20;  author nelson;  state Exp;
  96. branches ;
  97. next     1.12;
  98.  
  99. 1.12
  100. date     87.10.05.12.51.50;  author nelson;  state Exp;
  101. branches ;
  102. next     1.11;
  103.  
  104. 1.11
  105. date     87.09.10.14.40.39;  author nelson;  state Exp;
  106. branches ;
  107. next     1.10;
  108.  
  109. 1.10
  110. date     87.08.10.10.48.29;  author nelson;  state Exp;
  111. branches ;
  112. next     1.9;
  113.  
  114. 1.9
  115. date     87.07.14.14.39.27;  author nelson;  state Exp;
  116. branches ;
  117. next     1.8;
  118.  
  119. 1.8
  120. date     87.07.14.11.32.41;  author brent;  state Exp;
  121. branches ;
  122. next     1.7;
  123.  
  124. 1.7
  125. date     87.06.03.19.31.02;  author nelson;  state Exp;
  126. branches ;
  127. next     1.6;
  128.  
  129. 1.6
  130. date     87.06.01.15.42.12;  author nelson;  state Exp;
  131. branches ;
  132. next     1.5;
  133.  
  134. 1.5
  135. date     86.12.16.13.22.11;  author nelson;  state Exp;
  136. branches ;
  137. next     1.4;
  138.  
  139. 1.4
  140. date     86.11.26.17.49.57;  author nelson;  state Exp;
  141. branches ;
  142. next     1.3;
  143.  
  144. 1.3
  145. date     86.11.10.11.33.47;  author nelson;  state Exp;
  146. branches ;
  147. next     1.2;
  148.  
  149. 1.2
  150. date     86.09.19.18.18.11;  author nelson;  state Exp;
  151. branches ;
  152. next     1.1;
  153.  
  154. 1.1
  155. date     86.07.27.12.52.57;  author nelson;  state Exp;
  156. branches ;
  157. next     ;
  158.  
  159.  
  160. desc
  161. @@
  162.  
  163.  
  164. 1.30
  165. log
  166. @puts output in .fscheck.out even if disk already checked, updated ot
  167. ofs
  168. @
  169. text
  170. @/* 
  171.  * checkdir.c --
  172.  *
  173.  *    Routines to allow moving through a files block pointers.
  174.  *
  175.  * Copyright 1989 Regents of the University of California
  176.  * Permission to use, copy, modify, and distribute this
  177.  * software and its documentation for any purpose and without
  178.  * fee is hereby granted, provided that the above copyright
  179.  * notice appear in all copies.  The University of California
  180.  * makes no representations about the suitability of this
  181.  * software for any purpose.  It is provided "as is" without
  182.  * express or implied warranty.
  183.  */
  184.  
  185. #ifndef lint
  186. static char rcsid[] = "$Header: /sprite/src/cmds/fscheck/RCS/checkdir.c,v 1.29 90/10/10 15:29:03 mendel Exp Locker: jhh $ SPRITE (Berkeley)";
  187. #endif not lint
  188.  
  189. #include "option.h"
  190. #include "fscheck.h"
  191. #include "list.h"
  192. #include <stdio.h>
  193. #include <string.h>
  194. #include <ctype.h>
  195.  
  196. static    int        adding = 0;
  197. extern    int         writeDisk;
  198. static    char        pathName[FS_MAX_PATH_NAME_LENGTH];
  199. static    FdInfo        *descInfoArray;
  200. static    int    
  201. lostFoundFileNum = -1;
  202. extern    int        patchRoot;
  203. int            outputFileNum = -1;
  204. int            partFID;
  205. Ofs_DomainHeader        *domainPtr;
  206.  
  207. void            CheckDirEntry();
  208. static void        CheckDir();
  209. static ReturnStatus    AddToDirectory();
  210.  
  211. Fsdm_FileDescriptor    *rootFDPtr;
  212. Fsdm_FileDescriptor    *lostFoundFDPtr;
  213.  
  214. extern int verbose;
  215.  
  216. #define DIRFULL 2
  217.  
  218.  
  219. /*
  220.  *----------------------------------------------------------------------
  221.  *
  222.  * FetchFileDesc --
  223.  *
  224.  *    Return a file descriptor.
  225.  *
  226.  * Results:
  227.  *    1 if the file descriptor is successfully read or 0 if the descriptor 
  228.  *    was unreadable.
  229.  *
  230.  * Side effects:
  231.  *    A file descriptor may be allocated.
  232.  *
  233.  *----------------------------------------------------------------------
  234.  */
  235. int
  236. FetchFileDesc(fdNum, fdPtrPtr)
  237.     int            fdNum;        /* Number of descriptor to fetch. */
  238.     Fsdm_FileDescriptor    **fdPtrPtr;    /* Where to store ptr to descriptor. */
  239. {
  240.     ModListElement    *modElemPtr;
  241.     RelocListElement    *relocElemPtr;
  242.     static char        block[FS_BLOCK_SIZE];
  243.     int            blockNum;
  244.     int            offset;
  245.  
  246.     descInfoArray[fdNum].flags &= ~FD_MODIFIED;
  247.  
  248.     if (descInfoArray[fdNum].flags & FD_UNREADABLE) {
  249.     return(0);
  250.     }
  251.     if (descInfoArray[fdNum].flags & FD_RELOCATE) {
  252.     LIST_FORALL(relocList, (List_Links *)relocElemPtr) {
  253.         if (relocElemPtr->origFdNum == fdNum) {
  254.         *fdPtrPtr = relocElemPtr->fdPtr;
  255.         return(1);
  256.         }
  257.     }
  258.     Output(stderr, "FetchFileDesc: FD not found in relocate list.\n");
  259.     abort();
  260.     }
  261.     if (descInfoArray[fdNum].flags & ON_MOD_LIST) {
  262.     LIST_FORALL(modList, (List_Links *)modElemPtr) {
  263.         if (modElemPtr->fdNum == fdNum) {
  264.         *fdPtrPtr = modElemPtr->fdPtr;
  265.         return(1);
  266.         }
  267.     }
  268.     Output(stderr, "FetchFileDesc: FD not found in mod list.\n");
  269.     abort();
  270.     }
  271.     blockNum = domainPtr->fileDescOffset + fdNum / FSDM_FILE_DESC_PER_BLOCK;
  272.     offset = (fdNum & (FSDM_FILE_DESC_PER_BLOCK - 1)) * FSDM_MAX_FILE_DESC_SIZE;
  273.     if (Disk_BlockRead(partFID, domainPtr, blockNum, 1, 
  274.                (Address) block) < 0) {
  275.     OutputPerror("FetchFileDesc: Read failed on previously readable block");
  276.     exit(EXIT_READ_FAILURE);
  277.     }
  278.     Alloc(*fdPtrPtr,Fsdm_FileDescriptor,1);
  279.     if (tooBig) {
  280.     return 0;
  281.     }
  282.     bcopy((Address)&block[offset], (Address)*fdPtrPtr, 
  283.       sizeof(Fsdm_FileDescriptor));
  284.     return(1);
  285. }
  286.  
  287.  
  288. /*
  289.  *----------------------------------------------------------------------
  290.  *
  291.  * StoreFileDesc --
  292.  *
  293.  *    Store a file descriptor on disk.
  294.  *
  295.  * Results:
  296.  *    None.
  297.  *
  298.  * Side effects:
  299.  *    An FdCheckInfo struct is allocated.
  300.  *
  301.  *----------------------------------------------------------------------
  302.  */
  303. void
  304. StoreFileDesc(fdNum, fdPtr)
  305.     int            fdNum;
  306.     Fsdm_FileDescriptor    *fdPtr;
  307. {
  308.     ModListElement    *modElemPtr;
  309.  
  310.     if (descInfoArray[fdNum].flags & FD_MODIFIED) {
  311.     if (descInfoArray[fdNum].flags & ON_MOD_LIST) {
  312.         LIST_FORALL(modList, (List_Links *)modElemPtr) {
  313.         if (modElemPtr->fdNum == fdNum) {
  314.             /*
  315.              * The old fd may be in use on another list so we can't
  316.              * free it, but it may become unreferenced. 
  317.              */
  318.             modElemPtr->fdPtr = fdPtr;
  319.             return;
  320.         }
  321.         }
  322.         Output(stderr, "StoreFileDesc: FD not found in list.\n");
  323.         abort();
  324.     } else {
  325.         ModListElement    *modElemPtr;
  326.  
  327.         Alloc(modElemPtr,ModListElement,1);
  328.         if (tooBig) {
  329.         return;
  330.         }
  331.         descInfoArray[fdNum].flags |= ON_MOD_LIST;
  332.         modElemPtr->fdNum = fdNum;
  333.         modElemPtr->fdPtr = fdPtr;
  334.         List_Insert((List_Links *)modElemPtr, LIST_ATREAR(modList));
  335.     }
  336.     }
  337. }
  338.  
  339. /*
  340.  *----------------------------------------------------------------------
  341.  *
  342.  * MakePtrAccessible --
  343.  *
  344.  *    Make the pointer to the directory entry accessible.
  345.  *
  346.  * Results:
  347.  *    None.
  348.  *
  349.  * Side effects:
  350.  *    *indexInfoPtr modified.
  351.  *
  352.  *----------------------------------------------------------------------
  353.  */
  354. static int
  355. MakePtrAccessible(indexInfoPtr)
  356.     register    DirIndexInfo *indexInfoPtr;
  357. {
  358.     register int         *blockAddrPtr;
  359.     register Fsdm_FileDescriptor    *fdPtr;
  360.  
  361.     fdPtr = indexInfoPtr->fdPtr;
  362.  
  363.     blockAddrPtr = &indexInfoPtr->blockAddr;
  364.  
  365.     if (indexInfoPtr->indexType == INDIRECT) {
  366.     *blockAddrPtr = fdPtr->indirect[0];
  367.     } else {
  368.     *blockAddrPtr = fdPtr->indirect[1];
  369.     }
  370.  
  371.     /*
  372.      * Read first level block in.
  373.      */
  374.     if (indexInfoPtr->firstBlockNil) {
  375.     if (*blockAddrPtr == FSDM_NIL_INDEX) {
  376.         return(1);
  377.     }
  378.     if (Disk_FragRead(partFID, domainPtr,
  379.               *blockAddrPtr, FS_FRAGMENTS_PER_BLOCK,
  380.               indexInfoPtr->firstBlock) < 0) {
  381.         Output(stderr,"MakePtrAccessible: Read (1) failed block %d\n",
  382.                *blockAddrPtr);
  383.         return(0);
  384.     }
  385.     indexInfoPtr->firstBlockNil = 0;
  386.     }
  387.  
  388.     *blockAddrPtr = *(int *) (indexInfoPtr->firstBlock +
  389.                   sizeof(int) * indexInfoPtr->firstIndex);
  390.     if (indexInfoPtr->indexType == INDIRECT) {
  391.     return(1);
  392.     }
  393.  
  394.     /*
  395.      * Read second level block in.
  396.      */
  397.     if (*blockAddrPtr != FSDM_NIL_INDEX) {
  398.     if (Disk_FragRead(partFID, domainPtr,
  399.               *blockAddrPtr, FS_FRAGMENTS_PER_BLOCK,
  400.               indexInfoPtr->secondBlock) < 0) {
  401.         Output(stderr,"MakePtrAccessible: Read (2) failed block %d\n",
  402.                *blockAddrPtr);
  403.         return(0);
  404.     }
  405.     indexInfoPtr->secondBlockNil = 0;
  406.     *blockAddrPtr = *(int *) (indexInfoPtr->secondBlock +
  407.                   sizeof(int) * indexInfoPtr->secondIndex);
  408.     }
  409.     return(1);
  410. }
  411.  
  412.  
  413. /*
  414.  *----------------------------------------------------------------------
  415.  *
  416.  * GetFirstIndex --
  417.  *
  418.  *    Initialize the index structure.  This will set up the index info
  419.  *    structure so that it contains a pointer to the desired block pointer.
  420.  *
  421.  * Results:
  422.  *    1 if could set up the index, 0 if could not.
  423.  *
  424.  * Side effects:
  425.  *    The index structure is initialized.
  426.  *
  427.  *----------------------------------------------------------------------
  428.  */
  429. static int
  430. GetFirstIndex(blockNum, indexInfoPtr)
  431.     int                  blockNum;      /* Where to start indexing. */
  432.     register DirIndexInfo     *indexInfoPtr; /* Index structure to initialize.*/
  433. {
  434.     int            indirectBlock;
  435.     Fsdm_FileDescriptor    *fdPtr;
  436.  
  437.     indexInfoPtr->firstBlockNil = 1;
  438.     indexInfoPtr->secondBlockNil = 1;
  439.     indexInfoPtr->blockNum = blockNum;
  440.     indexInfoPtr->dirDirty = 0;
  441.  
  442.     fdPtr = indexInfoPtr->fdPtr;
  443.  
  444.     if (blockNum < FSDM_NUM_DIRECT_BLOCKS) {
  445.     /*
  446.      * This is a direct block.
  447.      */
  448.     indexInfoPtr->indexType = DIRECT;
  449.     indexInfoPtr->firstIndex = blockNum;
  450.     indexInfoPtr->blockAddr = fdPtr->direct[blockNum];
  451.     return(1);
  452.     }
  453.  
  454.     /*
  455.      * Is an indirect block.
  456.      */
  457.     blockNum -= FSDM_NUM_DIRECT_BLOCKS;
  458.     indirectBlock = blockNum / FSDM_INDICES_PER_BLOCK;
  459.     if (indirectBlock == 0) {
  460.     /*
  461.      * This is a singly indirect block.
  462.      */
  463.     indexInfoPtr->indexType = INDIRECT;
  464.     indexInfoPtr->firstIndex = blockNum;
  465.     } else {
  466.     /*
  467.      * This a doubly indirect block.
  468.      */
  469.     indexInfoPtr->indexType = DBL_INDIRECT;
  470.     indexInfoPtr->firstIndex = indirectBlock - 1;
  471.     indexInfoPtr->secondIndex = blockNum -
  472.                     indirectBlock * FSDM_INDICES_PER_BLOCK;
  473.     }
  474.  
  475.     /*
  476.      * Finish off by making the block pointer accessible.  This may include
  477.      * reading indirect blocks into the cache.
  478.      */
  479.     return(MakePtrAccessible(indexInfoPtr));
  480. }
  481.  
  482.  
  483. /*
  484.  *----------------------------------------------------------------------
  485.  *
  486.  * GetNextIndex --
  487.  *
  488.  *    Put the correct pointers in the index structure to access the
  489.  *    block after the current block.
  490.  *
  491.  * Results:
  492.  *    None.
  493.  *
  494.  * Side effects:
  495.  *    The allocation structure is modified.
  496.  *
  497.  *----------------------------------------------------------------------
  498.  */
  499. static int
  500. GetNextIndex(indexInfoPtr)
  501.     register DirIndexInfo *indexInfoPtr; /* Index structure to set up. */
  502. {
  503.     int            accessible = 0;
  504.     register Fsdm_FileDescriptor    *fdPtr;
  505.  
  506.     fdPtr = indexInfoPtr->fdPtr;
  507.  
  508.     indexInfoPtr->blockNum++;
  509.     indexInfoPtr->dirDirty = 0;
  510.  
  511.     /*
  512.      * Determine whether we are now in direct, indirect or doubly indirect
  513.      * blocks.
  514.      */
  515.     switch (indexInfoPtr->indexType) {
  516.     case DIRECT:
  517.         if (indexInfoPtr->blockNum < FSDM_NUM_DIRECT_BLOCKS) {
  518.         /*
  519.          * Still in the direct blocks.
  520.          */
  521.         indexInfoPtr->firstIndex++;
  522.         indexInfoPtr->blockAddr = 
  523.                 fdPtr->direct[indexInfoPtr->firstIndex];
  524.         accessible = 1;
  525.         } else {
  526.         /*
  527.          * Moved into indirect blocks.
  528.          */
  529.         indexInfoPtr->indexType = INDIRECT;
  530.         indexInfoPtr->firstIndex = 0;
  531.         }
  532.         break;
  533.     case INDIRECT:
  534.         if (indexInfoPtr->blockNum < FSDM_NUM_DIRECT_BLOCKS +
  535.             FSDM_INDICES_PER_BLOCK) {
  536.         /*
  537.          * Still in singly indirect blocks.
  538.          */
  539.         indexInfoPtr->firstIndex++;
  540.         indexInfoPtr->blockAddr = *(int *) (indexInfoPtr->firstBlock +
  541.                   sizeof(int) * indexInfoPtr->firstIndex);
  542.         accessible = 1;
  543.         break;
  544.        } else {
  545.         /*
  546.          * Moved into doubly indirect blocks.
  547.          */
  548.         indexInfoPtr->firstIndex = 0;
  549.         indexInfoPtr->secondIndex = 0;
  550.         indexInfoPtr->indexType = DBL_INDIRECT;
  551.         /*
  552.          * Free up the pointer block.
  553.          */
  554.         indexInfoPtr->firstBlockNil = 1;
  555.         }
  556.         break;
  557.     case DBL_INDIRECT:
  558.         indexInfoPtr->secondIndex++;
  559.         if (indexInfoPtr->secondIndex == FSDM_INDICES_PER_BLOCK) {
  560.         indexInfoPtr->firstIndex++;
  561.         indexInfoPtr->secondIndex = 0;
  562.         indexInfoPtr->secondBlockNil = 1;
  563.         } else {
  564.         indexInfoPtr->blockAddr = *(int *) (indexInfoPtr->secondBlock +
  565.                   sizeof(int) * indexInfoPtr->secondIndex);
  566.         accessible = 1;
  567.         }
  568.         break;
  569.     }
  570.  
  571.     /*
  572.      * Make the block pointers accessible if necessary.
  573.      */
  574.     if (!accessible) {
  575.     return(MakePtrAccessible(indexInfoPtr));
  576.     } else {
  577.     return(1);
  578.     }
  579. }
  580.  
  581.  
  582. /*
  583.  *----------------------------------------------------------------------
  584.  *
  585.  * OpenDir --
  586.  *
  587.  *    Set up the structure to allow moving through the given directory.
  588.  *
  589.  * Results:
  590.  *    None.
  591.  *
  592.  * Side effects:
  593.  *    The index structure is set up and *dirEntryPtrPtr set to point to
  594.  *    the first directory entry.
  595.  *
  596.  *----------------------------------------------------------------------
  597.  */
  598. void
  599. OpenDir(fdPtr, fdInfoPtr, indexInfoPtr, dirEntryPtrPtr)
  600.     Fsdm_FileDescriptor    *fdPtr;        /* The file descriptor for the
  601.                      * directory. */
  602.     FdInfo        *fdInfoPtr;    /* Descriptor status info for the
  603.                      * directory. */
  604.     DirIndexInfo     *indexInfoPtr;    /* Index info struct */
  605.     Fslcl_DirEntry        **dirEntryPtrPtr; /* Where to return a pointer to
  606.                        * the first directory entry. */
  607. {
  608.     int            fragsToRead;
  609.  
  610.     if (fdPtr->lastByte == -1) {
  611.     /*
  612.      * Empty directory.
  613.      */
  614.     *dirEntryPtrPtr = (Fslcl_DirEntry *) NULL;
  615.     return;
  616.     } else if ((fdPtr->lastByte + 1) % FSLCL_DIR_BLOCK_SIZE != 0) {
  617.     Output(stderr,
  618.     "Directory not multiple of directory block size. Directory corrected.\n");
  619.     foundError = 1;
  620.     fdPtr->lastByte = (fdPtr->lastByte & ~(FSLCL_DIR_BLOCK_SIZE - 1)) +
  621.                 FSLCL_DIR_BLOCK_SIZE - 1;
  622.     fdInfoPtr->flags |= FD_MODIFIED;
  623.     }
  624.     /*
  625.      * Initialize the index structure.
  626.      */
  627.     indexInfoPtr->fdPtr = fdPtr;
  628.     indexInfoPtr->fdInfoPtr = fdInfoPtr;
  629.     if (!GetFirstIndex(0, indexInfoPtr)) {
  630.     Output(stderr, "OpenDir: Error setting up index\n");
  631.     *dirEntryPtrPtr = (Fslcl_DirEntry *) NULL;
  632.     return;
  633.     }
  634.     /*
  635.      * Read in the first directory block.
  636.      */
  637.     if (fdPtr->lastByte >= FS_BLOCK_SIZE - 1) {
  638.     fragsToRead = FS_FRAGMENTS_PER_BLOCK;
  639.     } else {
  640.     fragsToRead = fdPtr->lastByte / FS_FRAGMENT_SIZE + 1;
  641.     }
  642.     indexInfoPtr->numFrags = fragsToRead;
  643.     if (Disk_FragRead(partFID, domainPtr,
  644.               indexInfoPtr->blockAddr + 
  645.               domainPtr->dataOffset * FS_FRAGMENTS_PER_BLOCK, 
  646.               fragsToRead, indexInfoPtr->dirBlock) < 0) {
  647.     Output(stderr, "OpenDir: Read failed block %d\n",
  648.                indexInfoPtr->blockAddr + 
  649.                        domainPtr->dataOffset * FS_FRAGMENTS_PER_BLOCK);
  650.     *dirEntryPtrPtr = (Fslcl_DirEntry *) NULL;
  651.     return;
  652.     } 
  653.     indexInfoPtr->dirOffset = 0;
  654.     *dirEntryPtrPtr = (Fslcl_DirEntry *) indexInfoPtr->dirBlock;
  655. }
  656.  
  657.  
  658. /*
  659.  *----------------------------------------------------------------------
  660.  *
  661.  * NextDirEntry --
  662.  *
  663.  *    Return a pointer to the next directory entry.
  664.  *
  665.  * Results:
  666.  *    None.
  667.  *
  668.  * Side effects:
  669.  *    The index structure is modified and *dirEntryPtrPtr set to point
  670.  *    to the next directory entry.
  671.  *
  672.  *----------------------------------------------------------------------
  673.  */
  674. void
  675. NextDirEntry(indexInfoPtr, dirEntryPtrPtr)
  676.     DirIndexInfo     *indexInfoPtr;
  677.     Fslcl_DirEntry        **dirEntryPtrPtr;
  678. {
  679.     int            firstDirByte;
  680.     int            lastByte;
  681.     Fslcl_DirEntry        *dirEntryPtr;
  682.     int            fragsToRead;
  683.  
  684.     dirEntryPtr = *dirEntryPtrPtr;
  685.     indexInfoPtr->dirOffset += dirEntryPtr->recordLength;
  686.     lastByte = indexInfoPtr->fdPtr->lastByte;
  687.     firstDirByte = 
  688.      indexInfoPtr->dirOffset + indexInfoPtr->blockNum * FS_BLOCK_SIZE;
  689.     if (firstDirByte == lastByte + 1) {
  690.     /*
  691.      * We reached the end of the directory.  Write out the directory
  692.      * block if necessary.
  693.      */
  694.     *dirEntryPtrPtr = (Fslcl_DirEntry *) NULL;
  695.     if (indexInfoPtr->dirDirty && writeDisk) {
  696.         if (Disk_FragWrite(partFID, domainPtr,
  697.                   indexInfoPtr->blockAddr + 
  698.                   domainPtr->dataOffset * 
  699.                   FS_FRAGMENTS_PER_BLOCK, 
  700.                   indexInfoPtr->numFrags, 
  701.                   indexInfoPtr->dirBlock) < 0) {
  702.         Output(stderr, "NextDirEntry: Write failed block %d\n",
  703.                    indexInfoPtr->blockAddr + 
  704.                     domainPtr->dataOffset * FS_FRAGMENTS_PER_BLOCK);
  705.         }
  706.     }
  707.     return;
  708.     }
  709.  
  710.     if (indexInfoPtr->dirOffset < FS_BLOCK_SIZE) {
  711.     /*
  712.      * The next directory entry is in the current block.
  713.      */
  714.     dirEntryPtr = 
  715.          (Fslcl_DirEntry *) &(indexInfoPtr->dirBlock[indexInfoPtr->dirOffset]);
  716.     } else {
  717.     /*
  718.      * Have to move to the next directory block.  Write out the current
  719.      * block if necessary.
  720.      */
  721.     if (indexInfoPtr->dirDirty && writeDisk) {
  722.         if (Disk_FragWrite(partFID, domainPtr,
  723.                   indexInfoPtr->blockAddr + 
  724.                   domainPtr->dataOffset * 
  725.                   FS_FRAGMENTS_PER_BLOCK, 
  726.                   indexInfoPtr->numFrags, 
  727.                   indexInfoPtr->dirBlock) < 0) {
  728.         Output(stderr, "NextDirEntry: Write (2) failed block %d\n",
  729.                    indexInfoPtr->blockAddr + 
  730.                     domainPtr->dataOffset * FS_FRAGMENTS_PER_BLOCK);
  731.         *dirEntryPtrPtr = (Fslcl_DirEntry *) NULL;
  732.         return;
  733.         }
  734.     }
  735.     if (!GetNextIndex(indexInfoPtr)) {
  736.         Output(stderr, "NextDirEntry: Get index failed\n");
  737.         *dirEntryPtrPtr = (Fslcl_DirEntry *) NULL;
  738.         return;
  739.     }
  740.     if (lastByte - firstDirByte + 1 >= FS_BLOCK_SIZE ||
  741.         indexInfoPtr->blockNum >= FSDM_NUM_DIRECT_BLOCKS) {
  742.         fragsToRead = FS_FRAGMENTS_PER_BLOCK;
  743.     } else {
  744.         fragsToRead = (lastByte - firstDirByte) / FS_FRAGMENT_SIZE + 1;
  745.     }
  746.     indexInfoPtr->numFrags = fragsToRead;
  747.     if (Disk_FragRead(partFID, domainPtr,
  748.               indexInfoPtr->blockAddr + 
  749.               domainPtr->dataOffset * 
  750.               FS_FRAGMENTS_PER_BLOCK, 
  751.               fragsToRead, indexInfoPtr->dirBlock) < 0) {
  752.         Output(stderr, "NextDirEntry: Read failed block %d\n",
  753.                 indexInfoPtr->blockAddr + 
  754.                 domainPtr->dataOffset * FS_FRAGMENTS_PER_BLOCK);
  755.         *dirEntryPtrPtr = (Fslcl_DirEntry *) NULL;
  756.         return;
  757.     }
  758.     indexInfoPtr->dirOffset = 0;
  759.     dirEntryPtr = (Fslcl_DirEntry *) indexInfoPtr->dirBlock;
  760.     }
  761.  
  762.     *dirEntryPtrPtr = dirEntryPtr;
  763. }
  764.  
  765. static    DirIndexInfo    lostDirIndex;
  766. static  Fslcl_DirEntry    *lostDirEntryPtr;
  767.  
  768. static    DirIndexInfo    rootDirIndex;
  769. static  Fslcl_DirEntry    *rootDirEntryPtr;
  770. static    List_Links    orphanDirListHdr;
  771. static  List_Links    *orphanDirList = &orphanDirListHdr;
  772. typedef struct DirList {
  773.     List_Links    links;
  774.     int        dirNumber;
  775. } DirList;
  776.  
  777. /*
  778.  *----------------------------------------------------------------------
  779.  *
  780.  * CloseDir --
  781.  *
  782.  *    Flushes the current directory block to disk, if necessary.
  783.  *
  784.  * Results:
  785.  *    None.
  786.  *
  787.  * Side effects:
  788.  *    The index structure is modified and *dirEntryPtrPtr set to point
  789.  *    to the next directory entry.
  790.  *
  791.  *----------------------------------------------------------------------
  792.  */
  793. static void
  794. CloseDir(indexInfoPtr)
  795.     DirIndexInfo     *indexInfoPtr;
  796. {
  797.  
  798.     if (indexInfoPtr->dirDirty && writeDisk) {
  799.     if (Disk_FragWrite(partFID, domainPtr,
  800.               indexInfoPtr->blockAddr + 
  801.               domainPtr->dataOffset * 
  802.               FS_FRAGMENTS_PER_BLOCK, 
  803.               indexInfoPtr->numFrags, 
  804.               indexInfoPtr->dirBlock) < 0) {
  805.         Output(stderr, "CloseDir: Write (2) failed block %d\n",
  806.                indexInfoPtr->blockAddr + 
  807.                 domainPtr->dataOffset * FS_FRAGMENTS_PER_BLOCK);
  808.         return;
  809.     }
  810.     }
  811. }
  812.  
  813.  
  814. /*
  815.  *----------------------------------------------------------------------
  816.  *
  817.  * CheckDirTree --
  818.  *
  819.  *    Traverse the directory tree taking care of unreferenced files and
  820.  *    ensuring that link counts are correct.
  821.  *
  822.  * Results:
  823.  *    A return status.
  824.  *
  825.  * Side effects:
  826.  *    None.
  827.  *
  828.  *----------------------------------------------------------------------
  829.  */
  830. void
  831. CheckDirTree(partFIDParm, domainParmPtr, descInfoParm,fdBitmapPtr, bitmapPtr)
  832.     int            partFIDParm;
  833.     Ofs_DomainHeader    *domainParmPtr;
  834.     FdInfo        *descInfoParm;
  835.     u_char        *fdBitmapPtr;
  836.     u_char        *bitmapPtr;
  837. {
  838.     register    int    i;
  839.     register FdInfo    *fdInfoPtr;
  840.     Fslcl_DirEntry        *dirEntryPtr;
  841.     DirIndexInfo    dirIndex;
  842.     int            lostRootDirNum = -1;
  843.     int            unrefFiles = 0;
  844.     int            linkCountsCorrected = 0;
  845.     int            entryNum;
  846.     char        newFileName[100];
  847.     int            offset;
  848.     int            outputFileLength;
  849.     int            notAdded;
  850.  
  851.     partFID = partFIDParm;
  852.     domainPtr = domainParmPtr;
  853.     descInfoArray = descInfoParm;
  854.  
  855.     /*
  856.      * Check the root directory for consistency.
  857.      */
  858.     if (!FetchFileDesc(FSDM_ROOT_FILE_NUMBER, &rootFDPtr)) {
  859.     Output(stderr, "Unable to fetch file descriptor for root");
  860.     exit(EXIT_HARD_ERROR);
  861.     }
  862.  
  863.     if ((rootFDPtr->flags & FSDM_FD_FREE) ||
  864.     rootFDPtr->fileType != FS_DIRECTORY ||
  865.     rootFDPtr->magic != FSDM_FD_MAGIC ||
  866.     rootFDPtr->lastByte == -1) {
  867.     char *fileName;
  868.  
  869.     Output(stderr, "Root directory corrupted\n");
  870.     if (!patchRoot) {
  871.         exit(EXIT_HARD_ERROR);
  872.     } 
  873.     /*
  874.      * On 5/10/88 the root of a disk (/sprite) was overwritten.  It was
  875.      * patched by looking for directories with a ".." entry that
  876.      * referenced root, fileNumber == 2, and putting them into the
  877.      * root just like other orphans are put into lost+found.
  878.      */
  879.     Output(stderr, "Attempting to re-create the root\n");
  880.     lostRootDirNum = FSDM_ROOT_FILE_NUMBER;
  881.     List_Init(orphanDirList);
  882.     lostFoundFileNum = FSDM_ROOT_FILE_NUMBER + 1;
  883.     if (MakeRoot(domainPtr, bitmapPtr, rootFDPtr) != SUCCESS) {
  884.         Output(stderr,"Unable to reinitialize root fd.\n");
  885.         exit(EXIT_HARD_ERROR);
  886.     }
  887.     OpenDir(rootFDPtr, &descInfoArray[FSDM_ROOT_FILE_NUMBER], &rootDirIndex, 
  888.         &rootDirEntryPtr);
  889.     /*
  890.      * Create the "." and ".." entries in the trashed directory.  The
  891.      * above OpenDir call has set up rootDirEntryPtr to reference the
  892.      * first bytes in the directory.
  893.      */
  894.         descInfoArray[FSDM_ROOT_FILE_NUMBER].flags |= FD_ALLOCATED;
  895.     descInfoArray[FSDM_ROOT_FILE_NUMBER].flags |= FD_MODIFIED;
  896.     descInfoArray[FSDM_ROOT_FILE_NUMBER].flags |= IS_A_DIRECTORY;
  897.     MarkFDBitmap(FSDM_ROOT_FILE_NUMBER,fdBitmapPtr);
  898.     StoreFileDesc(FSDM_ROOT_FILE_NUMBER, rootFDPtr);
  899.     fileName = ".";
  900.     rootDirEntryPtr->fileNumber = lostRootDirNum;
  901.     rootDirEntryPtr->nameLength = strlen(fileName);
  902.     rootDirEntryPtr->recordLength =
  903.         Fslcl_DirRecLength(rootDirEntryPtr->nameLength);
  904.     (void)strcpy(rootDirEntryPtr->fileName, fileName);
  905.     offset = rootDirEntryPtr->recordLength;
  906.     NextDirEntry(&rootDirIndex, &rootDirEntryPtr);
  907.  
  908.     fileName = "..";
  909.     rootDirEntryPtr->fileNumber = lostRootDirNum;
  910.     rootDirEntryPtr->nameLength = strlen(fileName);
  911.     rootDirEntryPtr->recordLength = FSLCL_DIR_BLOCK_SIZE - offset;
  912.     (void)strcpy(rootDirEntryPtr->fileName, fileName);
  913.     NextDirEntry(&rootDirIndex, &rootDirEntryPtr);
  914.     for(i = 1; i < FS_BLOCK_SIZE / FSLCL_DIR_BLOCK_SIZE; i++) {
  915.         rootDirEntryPtr->fileNumber = 0;
  916.         rootDirEntryPtr->recordLength = FSLCL_DIR_BLOCK_SIZE;
  917.         rootDirEntryPtr->nameLength = 0;
  918.         NextDirEntry(&rootDirIndex, &rootDirEntryPtr);
  919.     }
  920.     rootDirIndex.dirDirty = 1;
  921.     CloseDir(&rootDirIndex);
  922.     /*
  923.      * If the root is corrupted then don't set the checked bit in the
  924.      * summary sector. I'm kind of paranoid about the above code
  925.      * working correctly.
  926.      */
  927.     setCheckedBit = FALSE;
  928.     }
  929.     OpenDir(rootFDPtr, &descInfoArray[FSDM_ROOT_FILE_NUMBER], &dirIndex, 
  930.         &dirEntryPtr);
  931.     if (dirEntryPtr == (Fslcl_DirEntry *)NULL) {
  932.     exit(EXIT_HARD_ERROR);
  933.     }
  934.  
  935.     (void)strcpy(pathName, "/");
  936.     entryNum = 0;
  937.     if (outputFileName != NULL) {
  938.     outputFileLength = strlen(outputFileName);
  939.     }
  940.     while (dirEntryPtr != (Fslcl_DirEntry *) NULL) {
  941.     /*
  942.      * Go through the root directory checking each directory entry.
  943.      */
  944.     CheckDirEntry(entryNum, &dirIndex, dirEntryPtr);
  945.     if (dirEntryPtr->nameLength > 0 && 
  946.         strncmp("lost+found", dirEntryPtr->fileName,
  947.             dirEntryPtr->nameLength)  == 0) {
  948.         lostFoundFileNum = dirEntryPtr->fileNumber;
  949.     } else if (rawOutput && outputFileName != NULL &&
  950.         (dirEntryPtr->nameLength == outputFileLength) && 
  951.         strncmp(outputFileName, dirEntryPtr->fileName, outputFileLength)
  952.         == 0) {
  953.         outputFileNum = dirEntryPtr->fileNumber;
  954.     }
  955.     NextDirEntry(&dirIndex, &dirEntryPtr);
  956.     entryNum++;
  957.     }
  958.     CloseDir(&dirIndex);
  959.     if (tooBig) {
  960.     return;
  961.     }
  962.  
  963.     if (lostFoundFileNum == -1) {
  964.     Output(stderr, "lost+found missing from root\n");
  965.     lostFoundFileNum = -1;
  966.     } else {
  967.     /*
  968.      * Make sure that lost and found is consistent.
  969.      */
  970.     if (!FetchFileDesc(lostFoundFileNum, &lostFoundFDPtr)) {
  971.         Output(stderr, "Unable to fetch file descriptor for lost+found");
  972.         exit(EXIT_HARD_ERROR);
  973.     }
  974.  
  975.     (void)strcpy(pathName, "/lost+found/");
  976.     fdInfoPtr = &descInfoArray[lostFoundFileNum];
  977.     if (lostFoundFDPtr->fileType != FS_DIRECTORY) {
  978.         Output(stderr,
  979.          "Lost+found isn't a directory!  Should remove and recreate.\n");
  980.         lostFoundFileNum = -1;
  981.     } else {
  982.         int    dirOK;
  983.  
  984.         CheckDir(lostFoundFileNum, lostFoundFDPtr, fdInfoPtr,
  985.             FSDM_ROOT_FILE_NUMBER, lostRootDirNum,    &dirOK);
  986.         if (dirOK) {
  987.         OpenDir(lostFoundFDPtr, fdInfoPtr, &lostDirIndex,
  988.                  &lostDirEntryPtr);
  989.         if (lostDirEntryPtr == (Fslcl_DirEntry *)NULL) {
  990.             Output(stderr, "Could not open lost+found\n");
  991.             lostFoundFileNum = -1;
  992.         } else {
  993.             descInfoArray[lostFoundFileNum].flags |= FD_SEEN;
  994.         }
  995.         } else {
  996.         lostFoundFileNum = -1;
  997.         }
  998.     }
  999.     }
  1000.     if (tooBig) {
  1001.     return;
  1002.     }
  1003.  
  1004.     /*
  1005.      * Check all file descriptors.  If we are re-creating the root this
  1006.      * has a side-effect of preparing a list of the orphans of the root.
  1007.      */
  1008.     for (i = 0, fdInfoPtr = descInfoArray;
  1009.      i < domainPtr->numFileDesc; 
  1010.      i++, fdInfoPtr++) {
  1011.     int            dirOK;
  1012.     Fsdm_FileDescriptor    *newFDPtr;
  1013.  
  1014.     if (!(fdInfoPtr->flags & FD_ALLOCATED) ||
  1015.          (fdInfoPtr->flags & FD_SEEN) ||
  1016.         !(fdInfoPtr->flags & IS_A_DIRECTORY)) {
  1017.         continue;
  1018.     }
  1019.     pathName[0] = '\0';
  1020.     if (!FetchFileDesc(i, &newFDPtr)) {
  1021.         Output(stderr,
  1022.             "Unable to fetch file descriptor for directory <%d>.\n", i);
  1023.         continue;
  1024.     }
  1025.     CheckDir(i, newFDPtr, fdInfoPtr, FSDM_ROOT_FILE_NUMBER,
  1026.         lostRootDirNum, &dirOK);
  1027.     StoreFileDesc(i, newFDPtr);
  1028.     }
  1029.  
  1030.     if (patchRoot && lostRootDirNum > 0) {
  1031.     DirList *dirListPtr;
  1032.  
  1033.     notAdded = 0;
  1034.  
  1035.     /*
  1036.      * Go through the list of root-orphans, putting them into the root.
  1037.      */
  1038.     OpenDir(rootFDPtr, &descInfoArray[FSDM_ROOT_FILE_NUMBER], &rootDirIndex, 
  1039.         &rootDirEntryPtr);
  1040.  
  1041.     LIST_FORALL(orphanDirList, (List_Links *)dirListPtr) {
  1042.         if (dirListPtr->dirNumber == lostFoundFileNum) {
  1043.         (void) strncpy(newFileName,"lost+found",100);
  1044.         } else { 
  1045.         (void) sprintf(newFileName, "%d", dirListPtr->dirNumber);
  1046.         }
  1047.         if (AddToDirectory(lostRootDirNum, rootFDPtr, &rootDirIndex,
  1048.              &rootDirEntryPtr, dirListPtr->dirNumber,
  1049.              newFileName,
  1050.              &descInfoArray[dirListPtr->dirNumber]) == DIRFULL) {
  1051.         if (notAdded == 0) {
  1052.             Output(stderr, 
  1053.             "Directory #%d full.  Couldn't insert file.\n", 
  1054.             lostRootDirNum);
  1055.         }
  1056.         notAdded++;
  1057.         }
  1058.     }
  1059.     if (notAdded > 0) {
  1060.         Output(stderr, "%d files not added to directory %d.\n", notAdded,
  1061.         lostRootDirNum);
  1062.     }
  1063.     if (rootDirIndex.dirDirty && writeDisk) {
  1064.         if (Disk_FragWrite(partFID, domainPtr,
  1065.                 rootDirIndex.blockAddr + domainPtr->dataOffset * 
  1066.                 FS_FRAGMENTS_PER_BLOCK, rootDirIndex.numFrags, 
  1067.                 rootDirIndex.dirBlock) < 0) {
  1068.         OutputPerror("CheckDirTree: Write failed");
  1069.         exit(EXIT_WRITE_FAILURE);
  1070.         }
  1071.     }
  1072.     }
  1073.     if (tooBig) {
  1074.     return;
  1075.     }
  1076.     /*
  1077.      * Now go through the file descriptors again this time putting all
  1078.      * unreferenced files in the lost and found directory and correcting
  1079.      * link counts.
  1080.      */
  1081.     notAdded = 0;
  1082.     for (i = 0, fdInfoPtr = descInfoArray;
  1083.      i <= domainPtr->numFileDesc; 
  1084.      i++, fdInfoPtr++) {
  1085.  
  1086.     /*
  1087.      * We have to do lost+found last because its link count is changed
  1088.      * when directories are added to it.
  1089.      */
  1090.     if (i == lostFoundFileNum) {
  1091.         continue;
  1092.     } else if (i == domainPtr->numFileDesc) {
  1093.         if (lostFoundFileNum == -1) {
  1094.         break;
  1095.         }
  1096.         i = lostFoundFileNum;
  1097.         fdInfoPtr = &descInfoArray[lostFoundFileNum];
  1098.     }
  1099.     if (!(fdInfoPtr->flags & FD_ALLOCATED) ||
  1100.         (fdInfoPtr->flags & FD_UNREADABLE) ||
  1101.         i == FSDM_BAD_BLOCK_FILE_NUMBER) {
  1102.         continue;
  1103.     }
  1104.  
  1105.     if (!(fdInfoPtr->flags & FD_REFERENCED) && i != FSDM_ROOT_FILE_NUMBER) {
  1106.         if (verbose) {
  1107.         Output(stderr, "File %d is unreferenced\n", i);
  1108.         }
  1109.         unrefFiles++;
  1110.         foundError = 1;
  1111.         fflush(stderr);
  1112.         if (lostFoundFileNum != -1) {
  1113.         (void) sprintf(newFileName,"%d",i);
  1114.         if (AddToDirectory(lostFoundFileNum, lostFoundFDPtr, 
  1115.                 &lostDirIndex, &lostDirEntryPtr, i, 
  1116.                 newFileName, fdInfoPtr) == DIRFULL) {
  1117.             if (notAdded == 0) {
  1118.             Output(stderr, 
  1119.                 "Directory #%d full.  Couldn't insert file.\n", 
  1120.                 lostFoundFileNum);
  1121.             }
  1122.             notAdded++;
  1123.         }
  1124.         }
  1125.     } else if (fdInfoPtr->newLinkCount != fdInfoPtr->origLinkCount) {
  1126.         if (verbose) {
  1127.         Output(stderr,
  1128.             "Link count corrected for file %d.  Is %d should be %d.\n", 
  1129.             i, fdInfoPtr->origLinkCount, fdInfoPtr->newLinkCount);
  1130.         }
  1131.         linkCountsCorrected++;
  1132.         foundError = 1;
  1133.         fflush(stderr);
  1134.         if (i == FSDM_ROOT_FILE_NUMBER) {
  1135.         rootFDPtr->numLinks = fdInfoPtr->newLinkCount;
  1136.         fdInfoPtr->flags |= FD_MODIFIED;
  1137.         } else if (i == lostFoundFileNum) {
  1138.         lostFoundFDPtr->numLinks = fdInfoPtr->newLinkCount;
  1139.         fdInfoPtr->flags |= FD_MODIFIED;
  1140.         } else {
  1141.         Fsdm_FileDescriptor    *fdPtr;
  1142.         if (!FetchFileDesc(i, &fdPtr)) {
  1143.             Output(stderr,
  1144.       "Unable to fetch file descriptor for file <%d> to update link count", i);
  1145.         } else {
  1146.             fdPtr->numLinks = fdInfoPtr->newLinkCount;
  1147.             fdInfoPtr->flags |= FD_MODIFIED;
  1148.             StoreFileDesc(i, fdPtr);
  1149.         }
  1150.         }
  1151.     }
  1152.     if (i == lostFoundFileNum) {
  1153.         break;
  1154.     }
  1155.     }
  1156.     if (notAdded > 0) {
  1157.     Output(stderr, "%d files not added to directory %d.\n", notAdded,
  1158.         lostFoundFileNum);
  1159.     }
  1160.  
  1161.     if (unrefFiles > 0) {
  1162.     Output(stderr, "%d unreferenced files\n", unrefFiles);
  1163.     }
  1164.     if (linkCountsCorrected) {
  1165.     Output(stderr, "%d links counts corrected\n",
  1166.                linkCountsCorrected);
  1167.     }
  1168.  
  1169.     if (lostFoundFileNum != - 1 && lostDirIndex.dirDirty && writeDisk) {
  1170.     if (Disk_FragWrite(partFID, domainPtr,
  1171.             lostDirIndex.blockAddr + domainPtr->dataOffset * 
  1172.                 FS_FRAGMENTS_PER_BLOCK,
  1173.                 lostDirIndex.numFrags, 
  1174.                 lostDirIndex.dirBlock) < 0) {
  1175.         OutputPerror("CheckDirTree: Write failed");
  1176.         exit(EXIT_WRITE_FAILURE);
  1177.     }
  1178.     }
  1179.  
  1180.     StoreFileDesc(FSDM_ROOT_FILE_NUMBER, rootFDPtr);
  1181.     if (lostFoundFileNum != -1) {
  1182.     StoreFileDesc(lostFoundFileNum, lostFoundFDPtr);
  1183.     }
  1184. }
  1185.  
  1186.  
  1187. /*
  1188.  *----------------------------------------------------------------------
  1189.  *
  1190. * CheckDir --
  1191.  *
  1192.  *    Descend the directory tree starting from the given file descriptor.
  1193.  *
  1194.  * Results:
  1195.  *    None.
  1196.  *
  1197.  * Side effects:
  1198.  *    None.
  1199.  *
  1200.  *----------------------------------------------------------------------
  1201.  */
  1202.  
  1203. static void
  1204. CheckDir(fdNum, fdPtr, fdInfoPtr, parentFdNum, lostDirNum, dirOKPtr)
  1205.     int            fdNum;    /* Which file descriptor we are looking
  1206.                        at. */
  1207.     Fsdm_FileDescriptor    *fdPtr;        /* Pointer the file descriptor that
  1208.                      * we are looking at. */
  1209.     FdInfo        *fdInfoPtr;    /* Status of the file desc that we are
  1210.                        looking at. */
  1211.     int            parentFdNum;    /* File descriptor of parent directory.
  1212.     int            lostDirNum;    /* For re-creating trashed directories.
  1213.                      * This routine will add to a list
  1214.                      * of directories that were ref'ed
  1215.                      * by this 'lost directory' */
  1216.     int            *dirOKPtr;    /* Return 1 if the directory is
  1217.                      * not corrupted. */
  1218. {
  1219.     Fslcl_DirEntry     *dirEntryPtr;
  1220.     FdInfo     *newFDInfoPtr;
  1221.     DirIndexInfo dirIndex;
  1222.     int         entryNum;
  1223.     int        nullIndex;
  1224.  
  1225.     fdInfoPtr->flags |= FD_SEEN;
  1226.     *dirOKPtr = 0;
  1227.  
  1228.     /*
  1229.      * Open the directory.
  1230.      */
  1231.     OpenDir(fdPtr, fdInfoPtr, &dirIndex, &dirEntryPtr);
  1232.     nullIndex = strlen(pathName);
  1233.     if (dirEntryPtr == (Fslcl_DirEntry *) NULL) {    
  1234.     Output(stderr, "Empty directory %d %s changed to a file.\n",
  1235.                 fdNum, pathName);
  1236.     foundError = 1;
  1237.     fdPtr->fileType = FS_FILE;
  1238.     fdInfoPtr->flags |= FD_MODIFIED;
  1239.     return;
  1240.     }
  1241.     /*
  1242.      * Go through the directory.
  1243.      */
  1244.     entryNum = 0;
  1245.     if (debug) {
  1246.     Output(stderr,"Working on %s\n",pathName);
  1247.     }
  1248.     do {
  1249.     CheckDirEntry(entryNum, &dirIndex, dirEntryPtr);
  1250.     if (entryNum == 0) {
  1251.         /*
  1252.          * This should be "." and should point to the directory that
  1253.          * we are checking.
  1254.          */
  1255.         if (dirEntryPtr->fileNumber == 0 ||
  1256.         strncmp(".", dirEntryPtr->fileName, 
  1257.             dirEntryPtr->nameLength)  != 0) {
  1258.         Output(stderr,
  1259.             ". missing in directory %d %s.  Changed to a file.\n",
  1260.                    fdNum, pathName);
  1261.         foundError = 1;
  1262.         fdPtr->fileType = FS_FILE;
  1263.         fdInfoPtr->flags |= FD_MODIFIED;
  1264.         fdInfoPtr->flags &= ~IS_A_DIRECTORY;
  1265.         return;
  1266.         }
  1267.         if (dirEntryPtr->fileNumber != fdNum) {
  1268.         Output(stderr, 
  1269.                 ". does not point to self for directory %d %s\n",
  1270.                 fdNum, pathName);
  1271.         foundError = 1;
  1272.         dirEntryPtr->fileNumber = fdNum;
  1273.         dirIndex.dirDirty = 1;
  1274.         }
  1275.         fdInfoPtr->newLinkCount++;
  1276.     } else if (entryNum == 1) {
  1277.         /*
  1278.          * This should be ".."
  1279.          */
  1280.         if (dirEntryPtr->fileNumber == 0 ||
  1281.         strncmp("..", dirEntryPtr->fileName, 
  1282.             dirEntryPtr->nameLength) != 0) {
  1283.         Output(stderr,
  1284.             ".. missing in directory %d %s.  Changed to a file.\n",
  1285.                    fdNum, pathName);
  1286.         foundError = 1;
  1287.         fdPtr->fileType = FS_FILE;
  1288.         fdInfoPtr->flags |= FD_MODIFIED;
  1289.         fdInfoPtr->flags &= ~IS_A_DIRECTORY;
  1290.         return;
  1291.         }
  1292.         if (dirEntryPtr->fileNumber != parentFdNum) {
  1293.         Output(stderr, 
  1294.             ".. in directory %d %s pointed to %d, changed to %d.\n",
  1295.             fdNum, pathName, dirEntryPtr->fileNumber, parentFdNum);
  1296.         foundError = 1;
  1297.         dirEntryPtr->fileNumber = parentFdNum;
  1298.         dirIndex.dirDirty = 1;
  1299.         }
  1300.         /*
  1301.          * Look for orphans of lost directories.
  1302.          */
  1303.         if (lostDirNum > 0 &&
  1304.         dirEntryPtr->fileNumber == lostDirNum &&
  1305.         (fdNum != FSDM_ROOT_FILE_NUMBER ||
  1306.         lostDirNum != FSDM_ROOT_FILE_NUMBER)) {
  1307.         DirList *dirListPtr;
  1308.         Alloc(dirListPtr,DirList,1);
  1309.         if (!tooBig) {
  1310.             dirListPtr->dirNumber = fdNum;
  1311.             Output(stderr, "Found #%d, an orphan of dir #%d\n", 
  1312.                 fdNum, lostDirNum);
  1313.             List_Insert((List_Links *)dirListPtr,
  1314.                 LIST_ATREAR(orphanDirList));
  1315.             fdInfoPtr->flags |= FD_REFERENCED;
  1316.             fdInfoPtr->newLinkCount++;
  1317.         }
  1318.         } else {
  1319.         descInfoArray[dirEntryPtr->fileNumber].newLinkCount++;
  1320.         }
  1321.     } else if (dirEntryPtr->fileNumber != 0) {
  1322.         newFDInfoPtr = &descInfoArray[dirEntryPtr->fileNumber];
  1323.         newFDInfoPtr->newLinkCount++;
  1324.         newFDInfoPtr->flags |= FD_REFERENCED;
  1325.         if (!(newFDInfoPtr->flags & FD_SEEN) &&
  1326.            (newFDInfoPtr->flags & IS_A_DIRECTORY)) {
  1327.         int    dirOK;
  1328.         Fsdm_FileDescriptor    *newFDPtr;
  1329.  
  1330.         /*
  1331.          * Recurse on the directory.
  1332.          */
  1333.         (void)strncat(pathName, dirEntryPtr->fileName,
  1334.                   dirEntryPtr->nameLength);
  1335.         (void)strcat(pathName, "/");
  1336.         if (!FetchFileDesc(dirEntryPtr->fileNumber, &newFDPtr)) {
  1337.             Output(stderr,
  1338.             "Unable to fetch file descriptor for directory <%d>.\n",
  1339.                   dirEntryPtr->fileNumber);
  1340.         } else {
  1341.             CheckDir(dirEntryPtr->fileNumber, newFDPtr, 
  1342.                  newFDInfoPtr, fdNum, lostDirNum, &dirOK);
  1343.             pathName[nullIndex] = '\0';
  1344.             StoreFileDesc(dirEntryPtr->fileNumber, newFDPtr);
  1345.         }
  1346.         } 
  1347.     }
  1348.     NextDirEntry(&dirIndex, &dirEntryPtr);
  1349.     entryNum++;
  1350.     } while (dirEntryPtr != (Fslcl_DirEntry *) NULL);
  1351.  
  1352.     *dirOKPtr = 1;
  1353. }
  1354.  
  1355.  
  1356. /*
  1357.  *----------------------------------------------------------------------
  1358.  *
  1359.  * CheckDirEntry --
  1360.  *
  1361.  *    Perform checks on the current directory entry to make sure that
  1362.  *    it is has not been trashed.
  1363.  *
  1364.  * Results:
  1365.  *    None.
  1366.  *
  1367.  * Side effects:
  1368.  *    The directory may be modified.
  1369.  *
  1370.  *----------------------------------------------------------------------
  1371.  */
  1372.  
  1373. void
  1374. CheckDirEntry(entryNum, dirIndexPtr, dirEntryPtr)
  1375.     int        entryNum;    
  1376.     register    DirIndexInfo    *dirIndexPtr;
  1377.     register    Fslcl_DirEntry    *dirEntryPtr;
  1378. {
  1379.     int            dirBlockOffset;
  1380.     int            lastDirByte;
  1381.     char        buf[FS_MAX_NAME_LENGTH + 1];
  1382.     int            nameLength;
  1383.     register    char    *strPtr;
  1384.     int hadError = 0;
  1385.  
  1386.     dirBlockOffset = dirIndexPtr->dirOffset & (FSLCL_DIR_BLOCK_SIZE - 1);
  1387.     lastDirByte = dirBlockOffset + dirEntryPtr->recordLength;
  1388.  
  1389.     if (dirEntryPtr->fileNumber == 0) {
  1390.     nameLength = 0;
  1391.     } else {
  1392.     nameLength = dirEntryPtr->nameLength;
  1393.     }
  1394.  
  1395.     /*
  1396.      * First check the record length.
  1397.      */
  1398.     if (lastDirByte > FSLCL_DIR_BLOCK_SIZE ||
  1399.     lastDirByte % FSLCL_REC_LEN_GRAIN != 0 || 
  1400.     (FSLCL_DIR_BLOCK_SIZE - lastDirByte < FSLCL_DIR_ENTRY_HEADER &&
  1401.      lastDirByte != FSLCL_DIR_BLOCK_SIZE) ||
  1402.     dirEntryPtr->recordLength < Fslcl_DirRecLength(nameLength) ||
  1403.     dirEntryPtr->recordLength < 0) {
  1404.     Output(stderr,
  1405.     "Bad record length in directory.  Directory entry deleted from %s\n",
  1406.                pathName);
  1407.     foundError = 1;
  1408.     hadError = 1;
  1409.     /*
  1410.      * If the record length is screwed up, extend this record to the end
  1411.      * of the directory block and zap the file number.
  1412.      */
  1413.     dirEntryPtr->recordLength = FSLCL_DIR_BLOCK_SIZE - dirBlockOffset;
  1414.     dirEntryPtr->fileNumber = 0;
  1415.     dirIndexPtr->dirDirty = 1;
  1416.     return;
  1417.     }
  1418.     /*
  1419.      * Check the name length.
  1420.      */
  1421.     if (dirEntryPtr->fileNumber != 0) {
  1422.     int    nameError = 0;
  1423.     nameLength = strnlen(dirEntryPtr->fileName,
  1424.                  dirEntryPtr->recordLength - FSLCL_DIR_ENTRY_HEADER);
  1425.     if (nameLength != dirEntryPtr->nameLength) {
  1426.         bcopy(dirEntryPtr->fileName, buf, nameLength);
  1427.         buf[nameLength] = '\0';
  1428.         Output(stderr,
  1429.         "Name length %d wrong for directory entry: %s. Should be %d.\n", 
  1430.         dirEntryPtr->nameLength, buf, nameLength);
  1431.         foundError = 1;
  1432.         hadError = 1;
  1433.         dirEntryPtr->nameLength = nameLength;
  1434.         dirIndexPtr->dirDirty = 1;
  1435.         dirEntryPtr->recordLength = Fslcl_DirRecLength(nameLength);
  1436.     }
  1437.     /*
  1438.      * Make sure that the name contains printable characters.
  1439.      */
  1440.     strPtr = dirEntryPtr->fileName;
  1441.     while (*strPtr != '\0') {
  1442.         if (*strPtr < 0 || !isprint(*strPtr)) {
  1443.         *strPtr = '?';
  1444.         nameError = 1;
  1445.         }
  1446.         strPtr++;
  1447.     }
  1448.     if (nameError) {
  1449.         dirIndexPtr->dirDirty = 1;
  1450.         Output(stderr,
  1451.           "Non-printable characters in name for file %d in directory %s\n",
  1452.           dirEntryPtr->fileNumber, pathName);
  1453.         foundError = 1;
  1454.         hadError = 1;
  1455.     }
  1456.     }
  1457.  
  1458.     /*
  1459.      * Now check the file number.
  1460.      */
  1461.     if (dirEntryPtr->fileNumber < 0 ||
  1462.         dirEntryPtr->fileNumber >= domainPtr->numFileDesc) {
  1463.     Output(stderr, 
  1464.     "Bad file number in directory.  Directory entry deleted from %s.\n", 
  1465.                pathName);
  1466.     foundError = 1;
  1467.     hadError = 1;
  1468.     dirEntryPtr->fileNumber = 0;
  1469.     dirIndexPtr->dirDirty = 1;
  1470.     /*
  1471.      * Here we want to allow the ".." entry (entryNum = 0) to reference a
  1472.      * non-allocated file descriptor. What we have is an orphan directory so
  1473.      * we shouldn't nuke it just because something bad happened to its parent.
  1474.      */
  1475.     } else if (dirEntryPtr->fileNumber != 0 &&
  1476.               !(descInfoArray[dirEntryPtr->fileNumber].flags & FD_ALLOCATED) &&
  1477.           entryNum != 1)
  1478.           {
  1479.     Output(stderr, 
  1480.         "File %s%s references non-allocated descriptor %d. File Deleted.\n",
  1481.         pathName, dirEntryPtr->fileName,dirEntryPtr->fileNumber);
  1482.     foundError = 1;
  1483.     hadError = 1;
  1484.     dirEntryPtr->fileNumber = 0;
  1485.     dirIndexPtr->dirDirty = 1;
  1486.     }
  1487.     if (!hadError && debug) {
  1488.     Output(stderr,"Entry %s ok.\n",dirEntryPtr->fileName);
  1489.     }
  1490.     if (hadError) {
  1491.     Output(stderr,
  1492.     "Entry %s (%d) now has nameLength %d, recordLength %d, fileNumber %d.\n",
  1493.     dirEntryPtr->fileName, entryNum, dirEntryPtr->nameLength, 
  1494.     dirEntryPtr->recordLength, dirEntryPtr->fileNumber);
  1495.     }
  1496. }
  1497.  
  1498.  
  1499. /*
  1500.  *----------------------------------------------------------------------
  1501.  *
  1502.  * SetDotDot --
  1503.  *
  1504.  *    Make ".." in the given directory point to a given directory.
  1505.  *
  1506.  * Results:
  1507.  *    None.
  1508.  *
  1509.  * Side effects:
  1510.  *    ".." in the given directory is set to point to lost and found.
  1511.  *
  1512.  *----------------------------------------------------------------------
  1513.  */
  1514. static int
  1515. SetDotDot(dirNumber, dirFDPtr, fdPtr, fdInfoPtr)
  1516.     int            dirNumber;
  1517.     Fsdm_FileDescriptor    *dirFDPtr;
  1518.     Fsdm_FileDescriptor    *fdPtr;
  1519.     FdInfo        *fdInfoPtr;
  1520. {
  1521.     Fslcl_DirEntry         *dirEntryPtr;
  1522.     DirIndexInfo     dirIndex;
  1523.  
  1524.     /*
  1525.      * Open the directory.
  1526.      */
  1527.     OpenDir(fdPtr, fdInfoPtr, &dirIndex, &dirEntryPtr);
  1528.     if (dirEntryPtr == (Fslcl_DirEntry *)NULL) {
  1529.     Output(stderr, "SetDotDot: Could not open dir\n");
  1530.     return(0);
  1531.     }
  1532.     /*
  1533.      * Move past "." to "..".  Note that it is assume that this directory
  1534.      * has been checked and thus has both "." and "..".
  1535.      */
  1536.     NextDirEntry(&dirIndex, &dirEntryPtr);
  1537.     if (dirEntryPtr == (Fslcl_DirEntry *)NULL) {
  1538.     Output(stderr, "SetDotDot: Could not move from . to ..\n");
  1539.     return(0);
  1540.     }
  1541.  
  1542.     descInfoArray[dirNumber].newLinkCount++;
  1543.     descInfoArray[dirNumber].flags |= FD_MODIFIED;
  1544.     dirEntryPtr->fileNumber = dirNumber;
  1545.     if (writeDisk) {
  1546.     if (Disk_FragWrite(partFID, domainPtr, 
  1547.        dirIndex.blockAddr + domainPtr->dataOffset * FS_FRAGMENTS_PER_BLOCK,
  1548.        dirIndex.numFrags, dirIndex.dirBlock) < 0) {
  1549.         Output(stderr, "SetDotDot: Write failed block %d\n",
  1550.             dirIndex.blockAddr + 
  1551.                 domainPtr->dataOffset * FS_FRAGMENTS_PER_BLOCK);
  1552.         return(0);
  1553.     }
  1554.     }
  1555.     return(1);
  1556. }
  1557.  
  1558.  
  1559. /*
  1560.  *----------------------------------------------------------------------
  1561.  *
  1562.  * AddToDirectory --
  1563.  *
  1564.  *    Add the file descriptor to a directory.  
  1565.  *
  1566.  * Results:
  1567.  *    None.
  1568.  *
  1569.  * Side effects:
  1570.  *    The directory is modified to contain the orphaned file.
  1571.  *
  1572.  *----------------------------------------------------------------------
  1573.  */
  1574. static ReturnStatus
  1575. AddToDirectory(dirNumber, dirFDPtr, dirIndexPtr, dirEntryPtrPtr, fileNumber,
  1576.     fileName, fdInfoPtr)
  1577.     int            dirNumber;
  1578.     Fsdm_FileDescriptor    *dirFDPtr;
  1579.     DirIndexInfo    *dirIndexPtr;
  1580.     Fslcl_DirEntry        **dirEntryPtrPtr;
  1581.     int             fileNumber;
  1582.     char         *fileName;
  1583.     register    FdInfo    *fdInfoPtr;
  1584. {
  1585.     int             nameLength;
  1586.     int             recordLength;
  1587.     int             leftOver;
  1588.     int            oldRecLength;
  1589.     Fslcl_DirEntry        *dirEntryPtr;
  1590.     Fsdm_FileDescriptor    *fdPtr;
  1591.  
  1592.     adding = 1;
  1593.     nameLength = strlen(fileName);
  1594.     recordLength = Fslcl_DirRecLength(nameLength);
  1595.  
  1596.     dirEntryPtr = *dirEntryPtrPtr;
  1597.     while (dirEntryPtr != (Fslcl_DirEntry *) NULL) {
  1598.     if (dirEntryPtr->fileNumber != 0) {
  1599.         oldRecLength = Fslcl_DirRecLength(dirEntryPtr->nameLength);
  1600.         leftOver = dirEntryPtr->recordLength - oldRecLength;
  1601.         if (leftOver >= recordLength) {
  1602.         dirEntryPtr->recordLength = oldRecLength;
  1603.         dirEntryPtr = 
  1604.             (Fslcl_DirEntry *) ((int) dirEntryPtr + oldRecLength);
  1605.         dirEntryPtr->recordLength = leftOver;
  1606.         dirIndexPtr->dirOffset += oldRecLength;
  1607.         } else {
  1608.         NextDirEntry(dirIndexPtr, &dirEntryPtr);
  1609.         continue;
  1610.         }
  1611.     } else if (dirEntryPtr->recordLength < recordLength) {
  1612.         NextDirEntry(dirIndexPtr, &dirEntryPtr);
  1613.         continue;
  1614.     }
  1615.  
  1616.     if (!FetchFileDesc(fileNumber, &fdPtr)) {
  1617.         Output(stderr,
  1618.      "Unable to fetch file descriptor for file <%d> to add to directory <%d>\n",
  1619.               fileNumber, dirNumber);
  1620.         return FAILURE;
  1621.     }
  1622.     if (fdInfoPtr->flags & IS_A_DIRECTORY) {
  1623.         if (!SetDotDot(dirNumber, dirFDPtr, fdPtr, fdInfoPtr)) {
  1624.         *dirEntryPtrPtr = dirEntryPtr;
  1625.         return FAILURE;
  1626.         }
  1627.     }
  1628.     fdPtr->numLinks = fdInfoPtr->newLinkCount + 1;
  1629.     fdInfoPtr->flags |= FD_MODIFIED;
  1630.     StoreFileDesc(fileNumber, fdPtr);
  1631.  
  1632.     dirEntryPtr->fileNumber = fileNumber;
  1633.     dirEntryPtr->nameLength = nameLength;
  1634.     dirIndexPtr->dirDirty = 1;
  1635.     (void)strcpy(dirEntryPtr->fileName, fileName);
  1636.     leftOver = dirEntryPtr->recordLength - recordLength;
  1637.     if (leftOver > FSLCL_DIR_ENTRY_HEADER) {
  1638.         dirEntryPtr->recordLength = recordLength;
  1639.         dirEntryPtr =(Fslcl_DirEntry *) ((int) dirEntryPtr + recordLength);
  1640.         dirEntryPtr->fileNumber = 0;
  1641.         dirEntryPtr->recordLength = leftOver;
  1642.         dirIndexPtr->dirOffset += recordLength;
  1643.     } else {
  1644.         NextDirEntry(dirIndexPtr, &dirEntryPtr);
  1645.     }
  1646.     *dirEntryPtrPtr = dirEntryPtr;
  1647.     return SUCCESS;
  1648.     }
  1649.     return DIRFULL;
  1650. }
  1651.  
  1652. /*
  1653.  *----------------------------------------------------------------------
  1654.  *
  1655.  * MakeRoot --
  1656.  *
  1657.  *    Set up the file descriptor for the root directory.
  1658.  *
  1659.  * Results:
  1660.  *    Fill in the file descriptor.
  1661.  *
  1662.  * Side effects:
  1663.  *    Marks block 0 in the bitmap as in use.
  1664.  *
  1665.  *----------------------------------------------------------------------
  1666.  */
  1667. ReturnStatus
  1668. MakeRoot(domainPtr, bitmapPtr, fdPtr)
  1669.     Ofs_DomainHeader        *domainPtr;    /* Ptr to domain info */
  1670.     u_char            *bitmapPtr;    /* Ptr to cylinder data block
  1671.                          * bitmap */
  1672.     Fsdm_FileDescriptor        *fdPtr;
  1673. {
  1674.     Time     time;
  1675.     int     index;
  1676.     u_char     *bytePtr;
  1677.  
  1678.     fdPtr->flags = FSDM_FD_ALLOC;
  1679.     fdPtr->fileType = FS_DIRECTORY;
  1680.     fdPtr->permissions = 0755;
  1681.     fdPtr->uid = 0;
  1682.     fdPtr->gid = 0;
  1683.     fdPtr->lastByte = FS_BLOCK_SIZE-1;
  1684.     fdPtr->firstByte = -1;
  1685.     fdPtr->numLinks = 3;
  1686.     /*
  1687.      * Can't know device information because that depends on
  1688.      * the way the system is configured.
  1689.      */
  1690.     fdPtr->devServerID  -1;
  1691.     fdPtr->devType = -1;
  1692.     fdPtr->devUnit = -1;
  1693.  
  1694.     /*
  1695.      * Set the time stamps.  This assumes that universal time, not local
  1696.      * time, is used for time stamps.
  1697.      */
  1698.     Sys_GetTimeOfDay(&time, NULL, NULL);
  1699.     fdPtr->createTime = time.seconds;
  1700.     fdPtr->accessTime = 0;
  1701.     fdPtr->descModifyTime = time.seconds;
  1702.     fdPtr->dataModifyTime = time.seconds;
  1703.  
  1704.     /*
  1705.      * Place the data in the first filesystem block.
  1706.      */
  1707.     fdPtr->direct[0] = 0;
  1708.     bytePtr = GetBitmapPtr(domainPtr, bitmapPtr, 0);
  1709.     *bytePtr |= 0xf0;
  1710.     for (index = 1; index < FSDM_NUM_DIRECT_BLOCKS ; index++) {
  1711.     fdPtr->direct[index] = FSDM_NIL_INDEX;
  1712.     }
  1713.     for (index = 0; index < FSDM_NUM_INDIRECT_BLOCKS ; index++) {
  1714.     fdPtr->indirect[index] = FSDM_NIL_INDEX;
  1715.     }
  1716.     fdPtr->numKbytes = 4;
  1717.     fdPtr->version = 1;
  1718.     return SUCCESS;
  1719. }
  1720.  
  1721. /*
  1722.  *----------------------------------------------------------------------
  1723.  *
  1724.  * strnlen --
  1725.  *
  1726.  *    This is identical to strlen except that it will return N
  1727.  *    if the string length reaches N.
  1728.  *
  1729.  * Results:
  1730.  *    The return value is the number of characters in the
  1731.  *    string, not including the terminating zero byte.
  1732.  *
  1733.  * Side effects:
  1734.  *    None.
  1735.  *
  1736.  *----------------------------------------------------------------------
  1737.  */
  1738. int
  1739. strnlen(string, numChars)
  1740.     register char *string;        /* String whose length is wanted. */
  1741.     int           numChars;        /* Maximum number of chars to check. */
  1742. {
  1743.     register int result = -1;
  1744.  
  1745.     do {
  1746.     result += 1;
  1747.     } while (result < numChars && *string++ != 0);
  1748.     return(result);
  1749. }
  1750. @
  1751.  
  1752.  
  1753. 1.29
  1754. log
  1755. @Changes to reflect new OFS file system names.
  1756. @
  1757. text
  1758. @d17 1
  1759. a17 1
  1760. static char rcsid[] = "$Header: /sprite/src/cmds/fscheck/RCS/checkdir.c,v 1.28 90/10/10 11:22:10 jhh Exp Locker: mendel $ SPRITE (Berkeley)";
  1761. d429 1
  1762. a429 1
  1763. static void
  1764. d505 1
  1765. a505 1
  1766. static void
  1767. @
  1768.  
  1769.  
  1770. 1.28
  1771. log
  1772. @now can do raw output on any partition, fixed bug with ".."
  1773. @
  1774. text
  1775. @d17 1
  1776. a17 1
  1777. static char rcsid[] = "$Header: /sprite/src/cmds/fscheck.new/RCS/checkdir.c,v 1.27 90/05/01 15:36:42 jhh Exp Locker: jhh $ SPRITE (Berkeley)";
  1778. d31 2
  1779. a32 1
  1780. static    int        lostFoundFileNum = -1;
  1781. d36 1
  1782. a36 1
  1783. Fsdm_DomainHeader        *domainPtr;
  1784. d664 1
  1785. a664 1
  1786.     Fsdm_DomainHeader    *domainParmPtr;
  1787. d1500 1
  1788. a1500 1
  1789.     Fsdm_DomainHeader        *domainPtr;    /* Ptr to domain info */
  1790. @
  1791.  
  1792.  
  1793. 1.27
  1794. log
  1795. @ported to new Disk library
  1796. @
  1797. text
  1798. @d17 1
  1799. a17 1
  1800. static char rcsid[] = "$Header: /sprite/src/cmds/fscheck/RCS/checkdir.c,v 1.26 90/02/14 15:55:27 jhh Exp Locker: jhh $ SPRITE (Berkeley)";
  1801. d779 1
  1802. a779 1
  1803.     } else if (rootPart && outputFileName != NULL &&
  1804. d815 1
  1805. a815 1
  1806.             lostRootDirNum,    &dirOK);
  1807. d855 2
  1808. a856 1
  1809.     CheckDir(i, newFDPtr, fdInfoPtr, lostRootDirNum, &dirOK);
  1810. d1034 1
  1811. a1034 1
  1812. CheckDir(fdNum, fdPtr, fdInfoPtr, lostDirNum, dirOKPtr)
  1813. d1041 1
  1814. d1122 8
  1815. d1172 1
  1816. a1172 1
  1817.                  newFDInfoPtr, lostDirNum, &dirOK);
  1818. @
  1819.  
  1820.  
  1821. 1.26
  1822. log
  1823. @support for no recheck on reboot
  1824. @
  1825. text
  1826. @d17 1
  1827. a17 1
  1828. static char rcsid[] = "$Header: /a/newcmds/fscheck/RCS/checkdir.c,v 1.25 89/09/25 16:41:11 jhh Exp $ SPRITE (Berkeley)";
  1829. a20 1
  1830. #include "diskUtils.h"
  1831. @
  1832.  
  1833.  
  1834. 1.25
  1835. log
  1836. @Uses new fs module structure
  1837. @
  1838. text
  1839. @d17 1
  1840. a17 1
  1841. static char rcsid[] = "$Header: /a/newcmds/fscheck/RCS/checkdir.c,v 1.24 89/08/29 17:28:15 jhh Exp Locker: jhh $ SPRITE (Berkeley)";
  1842. d753 6
  1843. @
  1844.  
  1845.  
  1846. 1.24
  1847. log
  1848. @if lost+found doesn't exist we don't die anymore
  1849. @
  1850. text
  1851. @d17 1
  1852. a17 1
  1853. static char rcsid[] = "$Header: /a/newcmds/fscheck/RCS/checkdir.c,v 1.23 89/08/20 19:15:28 jhh Exp $ SPRITE (Berkeley)";
  1854. d36 1
  1855. a36 1
  1856. FsDomainHeader        *domainPtr;
  1857. d42 2
  1858. a43 2
  1859. FsFileDescriptor    *rootFDPtr;
  1860. FsFileDescriptor    *lostFoundFDPtr;
  1861. d69 1
  1862. a69 1
  1863.     FsFileDescriptor    **fdPtrPtr;    /* Where to store ptr to descriptor. */
  1864. d102 2
  1865. a103 2
  1866.     blockNum = domainPtr->fileDescOffset + fdNum / FS_FILE_DESC_PER_BLOCK;
  1867.     offset = (fdNum & (FS_FILE_DESC_PER_BLOCK - 1)) * FS_MAX_FILE_DESC_SIZE;
  1868. d109 1
  1869. a109 1
  1870.     Alloc(*fdPtrPtr,FsFileDescriptor,1);
  1871. d114 1
  1872. a114 1
  1873.       sizeof(FsFileDescriptor));
  1874. d137 1
  1875. a137 1
  1876.     FsFileDescriptor    *fdPtr;
  1877. d190 1
  1878. a190 1
  1879.     register FsFileDescriptor    *fdPtr;
  1880. d206 1
  1881. a206 1
  1882.     if (*blockAddrPtr == FS_NIL_INDEX) {
  1883. d228 1
  1884. a228 1
  1885.     if (*blockAddrPtr != FS_NIL_INDEX) {
  1886. d266 1
  1887. a266 1
  1888.     FsFileDescriptor    *fdPtr;
  1889. d275 1
  1890. a275 1
  1891.     if (blockNum < FS_NUM_DIRECT_BLOCKS) {
  1892. d288 2
  1893. a289 2
  1894.     blockNum -= FS_NUM_DIRECT_BLOCKS;
  1895.     indirectBlock = blockNum / FS_INDICES_PER_BLOCK;
  1896. d303 1
  1897. a303 1
  1898.                     indirectBlock * FS_INDICES_PER_BLOCK;
  1899. d335 1
  1900. a335 1
  1901.     register FsFileDescriptor    *fdPtr;
  1902. d348 1
  1903. a348 1
  1904.         if (indexInfoPtr->blockNum < FS_NUM_DIRECT_BLOCKS) {
  1905. d365 2
  1906. a366 2
  1907.         if (indexInfoPtr->blockNum < FS_NUM_DIRECT_BLOCKS +
  1908.             FS_INDICES_PER_BLOCK) {
  1909. d390 1
  1910. a390 1
  1911.         if (indexInfoPtr->secondIndex == FS_INDICES_PER_BLOCK) {
  1912. d431 1
  1913. a431 1
  1914.     FsFileDescriptor    *fdPtr;        /* The file descriptor for the
  1915. d436 1
  1916. a436 1
  1917.     FsDirEntry        **dirEntryPtrPtr; /* Where to return a pointer to
  1918. d445 1
  1919. a445 1
  1920.     *dirEntryPtrPtr = (FsDirEntry *) NULL;
  1921. d447 1
  1922. a447 1
  1923.     } else if ((fdPtr->lastByte + 1) % FS_DIR_BLOCK_SIZE != 0) {
  1924. d451 2
  1925. a452 2
  1926.     fdPtr->lastByte = (fdPtr->lastByte & ~(FS_DIR_BLOCK_SIZE - 1)) +
  1927.                 FS_DIR_BLOCK_SIZE - 1;
  1928. d462 1
  1929. a462 1
  1930.     *dirEntryPtrPtr = (FsDirEntry *) NULL;
  1931. d481 1
  1932. a481 1
  1933.     *dirEntryPtrPtr = (FsDirEntry *) NULL;
  1934. d485 1
  1935. a485 1
  1936.     *dirEntryPtrPtr = (FsDirEntry *) indexInfoPtr->dirBlock;
  1937. d508 1
  1938. a508 1
  1939.     FsDirEntry        **dirEntryPtrPtr;
  1940. d512 1
  1941. a512 1
  1942.     FsDirEntry        *dirEntryPtr;
  1943. d525 1
  1944. a525 1
  1945.     *dirEntryPtrPtr = (FsDirEntry *) NULL;
  1946. d546 1
  1947. a546 1
  1948.          (FsDirEntry *) &(indexInfoPtr->dirBlock[indexInfoPtr->dirOffset]);
  1949. d562 1
  1950. a562 1
  1951.         *dirEntryPtrPtr = (FsDirEntry *) NULL;
  1952. d568 1
  1953. a568 1
  1954.         *dirEntryPtrPtr = (FsDirEntry *) NULL;
  1955. d572 1
  1956. a572 1
  1957.         indexInfoPtr->blockNum >= FS_NUM_DIRECT_BLOCKS) {
  1958. d586 1
  1959. a586 1
  1960.         *dirEntryPtrPtr = (FsDirEntry *) NULL;
  1961. d590 1
  1962. a590 1
  1963.     dirEntryPtr = (FsDirEntry *) indexInfoPtr->dirBlock;
  1964. d597 1
  1965. a597 1
  1966. static  FsDirEntry    *lostDirEntryPtr;
  1967. d600 1
  1968. a600 1
  1969. static  FsDirEntry    *rootDirEntryPtr;
  1970. d664 1
  1971. a664 1
  1972.     FsDomainHeader    *domainParmPtr;
  1973. d671 1
  1974. a671 1
  1975.     FsDirEntry        *dirEntryPtr;
  1976. d689 1
  1977. a689 1
  1978.     if (!FetchFileDesc(FS_ROOT_FILE_NUMBER, &rootFDPtr)) {
  1979. d694 1
  1980. a694 1
  1981.     if ((rootFDPtr->flags & FS_FD_FREE) ||
  1982. d696 1
  1983. a696 1
  1984.     rootFDPtr->magic != FS_FD_MAGIC ||
  1985. d711 1
  1986. a711 1
  1987.     lostRootDirNum = FS_ROOT_FILE_NUMBER;
  1988. d713 1
  1989. a713 1
  1990.     lostFoundFileNum = FS_ROOT_FILE_NUMBER + 1;
  1991. d718 1
  1992. a718 1
  1993.     OpenDir(rootFDPtr, &descInfoArray[FS_ROOT_FILE_NUMBER], &rootDirIndex, 
  1994. d725 5
  1995. a729 5
  1996.         descInfoArray[FS_ROOT_FILE_NUMBER].flags |= FD_ALLOCATED;
  1997.     descInfoArray[FS_ROOT_FILE_NUMBER].flags |= FD_MODIFIED;
  1998.     descInfoArray[FS_ROOT_FILE_NUMBER].flags |= IS_A_DIRECTORY;
  1999.     MarkFDBitmap(FS_ROOT_FILE_NUMBER,fdBitmapPtr);
  2000.     StoreFileDesc(FS_ROOT_FILE_NUMBER, rootFDPtr);
  2001. d734 1
  2002. a734 1
  2003.         FsDirRecLength(rootDirEntryPtr->nameLength);
  2004. d742 1
  2005. a742 1
  2006.     rootDirEntryPtr->recordLength = FS_DIR_BLOCK_SIZE - offset;
  2007. d745 1
  2008. a745 1
  2009.     for(i = 1; i < FS_BLOCK_SIZE / FS_DIR_BLOCK_SIZE; i++) {
  2010. d747 1
  2011. a747 1
  2012.         rootDirEntryPtr->recordLength = FS_DIR_BLOCK_SIZE;
  2013. d754 1
  2014. a754 1
  2015.     OpenDir(rootFDPtr, &descInfoArray[FS_ROOT_FILE_NUMBER], &dirIndex, 
  2016. d756 1
  2017. a756 1
  2018.     if (dirEntryPtr == (FsDirEntry *)NULL) {
  2019. d765 1
  2020. a765 1
  2021.     while (dirEntryPtr != (FsDirEntry *) NULL) {
  2022. d814 1
  2023. a814 1
  2024.         if (lostDirEntryPtr == (FsDirEntry *)NULL) {
  2025. d837 1
  2026. a837 1
  2027.     FsFileDescriptor    *newFDPtr;
  2028. d862 1
  2029. a862 1
  2030.     OpenDir(rootFDPtr, &descInfoArray[FS_ROOT_FILE_NUMBER], &rootDirIndex, 
  2031. d925 1
  2032. a925 1
  2033.         i == FS_BAD_BLOCK_FILE_NUMBER) {
  2034. d929 1
  2035. a929 1
  2036.     if (!(fdInfoPtr->flags & FD_REFERENCED) && i != FS_ROOT_FILE_NUMBER) {
  2037. d958 1
  2038. a958 1
  2039.         if (i == FS_ROOT_FILE_NUMBER) {
  2040. d965 1
  2041. a965 1
  2042.         FsFileDescriptor    *fdPtr;
  2043. d1004 1
  2044. a1004 1
  2045.     StoreFileDesc(FS_ROOT_FILE_NUMBER, rootFDPtr);
  2046. d1031 1
  2047. a1031 1
  2048.     FsFileDescriptor    *fdPtr;        /* Pointer the file descriptor that
  2049. d1042 1
  2050. a1042 1
  2051.     FsDirEntry     *dirEntryPtr;
  2052. d1056 1
  2053. a1056 1
  2054.     if (dirEntryPtr == (FsDirEntry *) NULL) {    
  2055. d1120 2
  2056. a1121 2
  2057.         (fdNum != FS_ROOT_FILE_NUMBER ||
  2058.         lostDirNum != FS_ROOT_FILE_NUMBER)) {
  2059. d1143 1
  2060. a1143 1
  2061.         FsFileDescriptor    *newFDPtr;
  2062. d1165 1
  2063. a1165 1
  2064.     } while (dirEntryPtr != (FsDirEntry *) NULL);
  2065. d1192 1
  2066. a1192 1
  2067.     register    FsDirEntry    *dirEntryPtr;
  2068. d1201 1
  2069. a1201 1
  2070.     dirBlockOffset = dirIndexPtr->dirOffset & (FS_DIR_BLOCK_SIZE - 1);
  2071. d1213 5
  2072. a1217 5
  2073.     if (lastDirByte > FS_DIR_BLOCK_SIZE ||
  2074.     lastDirByte % FS_REC_LEN_GRAIN != 0 || 
  2075.     (FS_DIR_BLOCK_SIZE - lastDirByte < FS_DIR_ENTRY_HEADER &&
  2076.      lastDirByte != FS_DIR_BLOCK_SIZE) ||
  2077.     dirEntryPtr->recordLength < FsDirRecLength(nameLength) ||
  2078. d1228 1
  2079. a1228 1
  2080.     dirEntryPtr->recordLength = FS_DIR_BLOCK_SIZE - dirBlockOffset;
  2081. d1239 1
  2082. a1239 1
  2083.                  dirEntryPtr->recordLength - FS_DIR_ENTRY_HEADER);
  2084. d1250 1
  2085. a1250 1
  2086.         dirEntryPtr->recordLength = FsDirRecLength(nameLength);
  2087. d1332 2
  2088. a1333 2
  2089.     FsFileDescriptor    *dirFDPtr;
  2090.     FsFileDescriptor    *fdPtr;
  2091. d1336 1
  2092. a1336 1
  2093.     FsDirEntry         *dirEntryPtr;
  2094. d1343 1
  2095. a1343 1
  2096.     if (dirEntryPtr == (FsDirEntry *)NULL) {
  2097. d1352 1
  2098. a1352 1
  2099.     if (dirEntryPtr == (FsDirEntry *)NULL) {
  2100. d1393 1
  2101. a1393 1
  2102.     FsFileDescriptor    *dirFDPtr;
  2103. d1395 1
  2104. a1395 1
  2105.     FsDirEntry        **dirEntryPtrPtr;
  2106. d1404 2
  2107. a1405 2
  2108.     FsDirEntry        *dirEntryPtr;
  2109.     FsFileDescriptor    *fdPtr;
  2110. d1409 1
  2111. a1409 1
  2112.     recordLength = FsDirRecLength(nameLength);
  2113. d1412 1
  2114. a1412 1
  2115.     while (dirEntryPtr != (FsDirEntry *) NULL) {
  2116. d1414 1
  2117. a1414 1
  2118.         oldRecLength = FsDirRecLength(dirEntryPtr->nameLength);
  2119. d1419 1
  2120. a1419 1
  2121.             (FsDirEntry *) ((int) dirEntryPtr + oldRecLength);
  2122. d1452 1
  2123. a1452 1
  2124.     if (leftOver > FS_DIR_ENTRY_HEADER) {
  2125. d1454 1
  2126. a1454 1
  2127.         dirEntryPtr =(FsDirEntry *) ((int) dirEntryPtr + recordLength);
  2128. d1484 1
  2129. a1484 1
  2130.     FsDomainHeader        *domainPtr;    /* Ptr to domain info */
  2131. d1487 1
  2132. a1487 1
  2133.     FsFileDescriptor        *fdPtr;
  2134. d1493 1
  2135. a1493 1
  2136.     fdPtr->flags = FS_FD_ALLOC;
  2137. d1505 1
  2138. a1505 1
  2139.     fdPtr->devServerID = -1;
  2140. d1525 2
  2141. a1526 2
  2142.     for (index = 1; index < FS_NUM_DIRECT_BLOCKS ; index++) {
  2143.     fdPtr->direct[index] = FS_NIL_INDEX;
  2144. d1528 2
  2145. a1529 2
  2146.     for (index = 0; index < FS_NUM_INDIRECT_BLOCKS ; index++) {
  2147.     fdPtr->indirect[index] = FS_NIL_INDEX;
  2148. @
  2149.  
  2150.  
  2151. 1.23
  2152. log
  2153. @fixed link counts for lost+found, cleaned up lint errors
  2154. @
  2155. text
  2156. @d17 1
  2157. a17 1
  2158. static char rcsid[] = "$Header: /a/newcmds/fscheck/RCS/checkdir.c,v 1.22 89/06/22 17:50:37 jhh Exp $ SPRITE (Berkeley)";
  2159. d790 1
  2160. d917 3
  2161. @
  2162.  
  2163.  
  2164. 1.22
  2165. log
  2166. @doesn't tell you about each file that couldn't be inserted in a full
  2167. directory. Also fixed bug when output file is not specified in 
  2168. root partition.
  2169. @
  2170. text
  2171. @d17 1
  2172. a17 1
  2173. static char rcsid[] = "$Header: /a/newcmds/fscheck/RCS/checkdir.c,v 1.21 89/06/21 23:55:59 jhh Exp Locker: jhh $ SPRITE (Berkeley)";
  2174. a30 2
  2175. static    int        partFID;
  2176. static    FsDomainHeader    *domainPtr;
  2177. d35 2
  2178. d38 3
  2179. a40 3
  2180. void    CheckDirEntry();
  2181. void    CheckDir();
  2182. ReturnStatus    AddToDirectory();
  2183. d906 1
  2184. a906 1
  2185.      i < domainPtr->numFileDesc; 
  2186. d1213 2
  2187. a1214 1
  2188.     dirEntryPtr->recordLength < FsDirRecLength(nameLength)) {
  2189. d1219 1
  2190. a1219 1
  2191.         hadError = 1;
  2192. d1239 3
  2193. a1241 1
  2194.         Output(stderr,"Name length wrong for directory entry: %s.\n", buf);
  2195. d1246 1
  2196. d1300 6
  2197. @
  2198.  
  2199.  
  2200. 1.21
  2201. log
  2202. @Various bug fixes
  2203. @
  2204. text
  2205. @d17 1
  2206. a17 1
  2207. static char rcsid[] = "$Header: /a/newcmds/fscheck/RCS/checkdir.c,v 1.20 89/02/28 12:22:19 jhh Exp $ SPRITE (Berkeley)";
  2208. d40 1
  2209. a40 1
  2210. void    AddToDirectory();
  2211. d47 2
  2212. d680 1
  2213. d762 3
  2214. a764 1
  2215.     outputFileLength = strlen(outputFileName);
  2216. d856 2
  2217. d870 15
  2218. a884 4
  2219.         AddToDirectory(lostRootDirNum, rootFDPtr, &rootDirIndex,
  2220.                 &rootDirEntryPtr, dirListPtr->dirNumber,
  2221.                 newFileName,
  2222.                 &descInfoArray[dirListPtr->dirNumber]);
  2223. d904 1
  2224. d934 10
  2225. a943 2
  2226.         AddToDirectory(lostFoundFileNum, lostFoundFDPtr, &lostDirIndex,
  2227.                 &lostDirEntryPtr, i, newFileName, fdInfoPtr);
  2228. d976 5
  2229. d1375 1
  2230. a1375 1
  2231. static void
  2232. d1421 1
  2233. a1421 1
  2234.         return;
  2235. d1426 1
  2236. a1426 1
  2237.         return;
  2238. d1448 1
  2239. a1448 1
  2240.     return;
  2241. d1450 1
  2242. a1450 3
  2243.  
  2244.     Output(stderr, "Directory #%d full.  Couldn't insert %d\n", dirNumber,
  2245.            fileNumber);
  2246. @
  2247.  
  2248.  
  2249. 1.20
  2250. log
  2251. @Converted to new C library, added lots of new functionality
  2252. @
  2253. text
  2254. @d17 1
  2255. a17 1
  2256. static char rcsid[] = "$Header: /a/newcmds/fscheck/RCS/checkdir.c,v 1.19 88/12/05 14:33:50 douglis Exp $ SPRITE (Berkeley)";
  2257. d676 2
  2258. d733 1
  2259. d739 1
  2260. a739 2
  2261.     rootDirEntryPtr->recordLength =
  2262.         FsDirRecLength(rootDirEntryPtr->nameLength);
  2263. d742 6
  2264. a747 1
  2265.  
  2266. d759 1
  2267. d770 3
  2268. a772 3
  2269.         dirEntryPtr->nameLength > 0 && 
  2270.         strncmp(outputFileName, dirEntryPtr->fileName,
  2271.             dirEntryPtr->nameLength)  == 0) {
  2272. d887 1
  2273. a887 1
  2274.      ; 
  2275. @
  2276.  
  2277.  
  2278. 1.19
  2279. log
  2280. @Converted over to the new C library.
  2281. @
  2282. text
  2283. @d6 8
  2284. a13 2
  2285.  * Copyright 1986 Regents of the University of California
  2286.  * All rights reserved.
  2287. d17 1
  2288. a17 1
  2289. static char rcsid[] = "$Header: checkdir.c,v 1.18 88/09/20 15:14:07 nelson Exp $ SPRITE (Berkeley)";
  2290. d36 1
  2291. d71 1
  2292. a71 1
  2293.     char        block[FS_BLOCK_SIZE];
  2294. a73 1
  2295.     ReturnStatus    status;
  2296. d83 1
  2297. a83 1
  2298.         *fdPtrPtr = &relocElemPtr->fd;
  2299. d87 1
  2300. a87 1
  2301.     fprintf(stderr, "FetchFileDesc: FD not found in relocate list.\n");
  2302. d93 1
  2303. a93 1
  2304.         *fdPtrPtr = &modElemPtr->fd;
  2305. d97 1
  2306. a97 1
  2307.     fprintf(stderr, "FetchFileDesc: FD not found in mod list.\n");
  2308. a99 1
  2309.  
  2310. d104 2
  2311. a105 2
  2312.     perror("FetchFileDesc: Read failed on previously readable block");
  2313.     exit(EXIT_HARD_ERR);
  2314. d107 4
  2315. a110 1
  2316.     *fdPtrPtr = (FsFileDescriptor *)malloc(sizeof(FsFileDescriptor));
  2317. d143 5
  2318. d151 1
  2319. a151 1
  2320.         fprintf(stderr, "StoreFileDesc: FD not found in list.\n");
  2321. d155 5
  2322. a159 1
  2323.     
  2324. a160 1
  2325.         modElemPtr = (ModListElement *)malloc(sizeof(ModListElement));
  2326. d162 1
  2327. a162 2
  2328.         bcopy((Address)fdPtr, (Address)&modElemPtr->fd,
  2329.           sizeof(FsFileDescriptor));
  2330. a163 1
  2331.         free((Address)fdPtr);
  2332. a166 1
  2333.  
  2334. a188 1
  2335.     ReturnStatus        status;
  2336. d210 1
  2337. a210 1
  2338.         fprintf(stderr,"MakePtrAccessible: Read (1) failed block %d\n",
  2339. d230 1
  2340. a230 1
  2341.         fprintf(stderr,"MakePtrAccessible: Read (2) failed block %d\n",
  2342. d446 1
  2343. a446 1
  2344.     fprintf(stderr,
  2345. d459 1
  2346. a459 1
  2347.     fprintf(stderr, "OpenDir: Error setting up index\n");
  2348. d476 1
  2349. a476 1
  2350.     fprintf(stderr, "OpenDir: Read failed block %d\n",
  2351. d531 1
  2352. a531 1
  2353.         fprintf(stderr, "NextDirEntry: Write failed block %d\n",
  2354. d557 1
  2355. a557 1
  2356.         fprintf(stderr, "NextDirEntry: Write (2) failed block %d\n",
  2357. d565 1
  2358. a565 1
  2359.         fprintf(stderr, "NextDirEntry: Get index failed\n");
  2360. d581 1
  2361. a581 1
  2362.         fprintf(stderr, "NextDirEntry: Read failed block %d\n",
  2363. d605 21
  2364. d627 15
  2365. d660 1
  2366. a660 1
  2367. CheckDirTree(partFIDParm, domainParmPtr, descInfoParm)
  2368. d664 2
  2369. d674 2
  2370. d685 2
  2371. a686 2
  2372.     fprintf(stderr, "Unable to fetch file descriptor for root");
  2373.     exit(EXIT_HARD_ERR);
  2374. d691 1
  2375. d693 3
  2376. a695 1
  2377.     fprintf(stderr, "Root directory corrupted\n");
  2378. d697 2
  2379. a698 5
  2380.         exit(EXIT_HARD_ERR);
  2381.     } else if (rootFDPtr->lastByte == -1) {
  2382.         fprintf(stderr, "Can't fix empty root (can you?)\n");
  2383.         exit(EXIT_HARD_ERR);
  2384.     }
  2385. d705 1
  2386. a705 1
  2387.     fprintf(stderr, "Attempting to re-create the root\n");
  2388. d709 4
  2389. d715 51
  2390. a765 2
  2391.     if (rootDirEntryPtr == (FsDirEntry *)NULL) {
  2392.         exit(EXIT_HARD_ERR);
  2393. d767 2
  2394. a768 16
  2395.     } else {
  2396.     OpenDir(rootFDPtr, &descInfoArray[FS_ROOT_FILE_NUMBER], &dirIndex, 
  2397.         &dirEntryPtr);
  2398.     
  2399.     (void)strcpy(pathName, "/");
  2400.     while (dirEntryPtr != (FsDirEntry *) NULL) {
  2401.         /*
  2402.          * Go through the root directory checking each directory entry.
  2403.          */
  2404.         CheckDirEntry(&dirIndex, dirEntryPtr);
  2405.         if (strncmp("lost+found", dirEntryPtr->fileName,
  2406.             dirEntryPtr->nameLength)  == 0) {
  2407.         lostFoundFileNum = dirEntryPtr->fileNumber;
  2408.         }
  2409.         NextDirEntry(&dirIndex, &dirEntryPtr);
  2410.     }
  2411. d770 4
  2412. d776 1
  2413. a776 1
  2414.     fprintf(stderr, "lost+found missing from root\n");
  2415. d782 2
  2416. a783 2
  2417.         fprintf(stderr, "Unable to fetch file descriptor for lost+found");
  2418.         exit(EXIT_HARD_ERR);
  2419. d789 1
  2420. a789 1
  2421.         fprintf(stderr,
  2422. d801 1
  2423. a801 1
  2424.             fprintf(stderr, "Could not open lost+found\n");
  2425. d803 2
  2426. d811 3
  2427. d832 2
  2428. a833 2
  2429.         fprintf(stderr,
  2430.             "Unable to fetch file descriptor for directory <%d>", i);
  2431. a841 1
  2432.     char *fileName;
  2433. a843 29
  2434.      * Create the "." and ".." entries in the trashed directory.  The
  2435.      * above OpenDir call has set up rootDirEntryPtr to reference the
  2436.      * first bytes in the directory.
  2437.      */
  2438.  
  2439.     fileName = ".";
  2440.     rootDirEntryPtr->fileNumber = lostRootDirNum;
  2441.     rootDirEntryPtr->nameLength = strlen(fileName);
  2442.     rootDirEntryPtr->recordLength =
  2443.         FsDirRecLength(rootDirEntryPtr->nameLength);
  2444.     (void)strcpy(rootDirEntryPtr->fileName, fileName);
  2445.     NextDirEntry(&rootDirIndex, &rootDirEntryPtr);
  2446.  
  2447.     fileName = "..";
  2448.     rootDirEntryPtr->fileNumber = lostRootDirNum;
  2449.     rootDirEntryPtr->nameLength = strlen(fileName);
  2450.     rootDirEntryPtr->recordLength =
  2451.         FsDirRecLength(rootDirEntryPtr->nameLength);
  2452.     (void)strcpy(rootDirEntryPtr->fileName, fileName);
  2453.     NextDirEntry(&rootDirIndex, &rootDirEntryPtr);
  2454.  
  2455.     while(rootDirEntryPtr != (FsDirEntry *)NULL) {
  2456.         CheckDirEntry(&rootDirIndex, rootDirEntryPtr);
  2457.         NextDirEntry(&rootDirIndex, &rootDirEntryPtr);
  2458.     }
  2459.     rootFDPtr->fileType = FS_DIRECTORY;
  2460.     descInfoArray[FS_ROOT_FILE_NUMBER].flags |= FD_MODIFIED;
  2461.  
  2462.     /*
  2463. d850 5
  2464. d857 1
  2465. d865 2
  2466. a866 2
  2467.         perror("CheckDirTree: Write failed");
  2468.         exit(EXIT_HARD_ERR);
  2469. d870 3
  2470. d879 1
  2471. a879 1
  2472.      i < domainPtr->numFileDesc; 
  2473. d882 10
  2474. d900 1
  2475. a900 1
  2476.         fprintf(stderr, "File %d is unreferenced\n", i);
  2477. d906 1
  2478. d908 1
  2479. a908 1
  2480.                 &lostDirEntryPtr, i, fdInfoPtr);
  2481. d912 1
  2482. a912 1
  2483.         fprintf(stderr,
  2484. d928 1
  2485. a928 1
  2486.             fprintf(stderr,
  2487. d937 3
  2488. d942 1
  2489. a942 1
  2490.     fprintf(stderr, "%d unreferenced files\n", unrefFiles);
  2491. d945 1
  2492. a945 1
  2493.     fprintf(stderr, "%d links counts corrected\n",
  2494. d955 2
  2495. a956 2
  2496.         perror("CheckDirTree: Write failed");
  2497.         exit(EXIT_HARD_ERR);
  2498. d970 1
  2499. a970 1
  2500.  * CheckDir --
  2501. d1013 1
  2502. a1013 1
  2503.     fprintf(stderr, "Empty directory %d %s changed to a file.\n",
  2504. d1024 3
  2505. d1028 1
  2506. a1028 1
  2507.     CheckDirEntry(&dirIndex, dirEntryPtr);
  2508. d1037 1
  2509. a1037 1
  2510.         fprintf(stderr,
  2511. d1047 1
  2512. a1047 1
  2513.         fprintf(stderr, 
  2514. d1062 1
  2515. a1062 1
  2516.         fprintf(stderr,
  2517. a1070 1
  2518.         descInfoArray[dirEntryPtr->fileNumber].newLinkCount++;
  2519. d1075 3
  2520. a1077 1
  2521.         dirEntryPtr->fileNumber == lostDirNum) {
  2522. d1079 12
  2523. a1090 8
  2524.         dirListPtr = (DirList *)malloc(sizeof(DirList));
  2525.         dirListPtr->dirNumber = fdNum;
  2526.         fprintf(stderr, "Found #%d, an orphan of dir #%d\n", 
  2527.             fdNum, lostDirNum);
  2528.         List_Insert((List_Links *)dirListPtr,
  2529.                 LIST_ATREAR(orphanDirList));
  2530.         fdInfoPtr->flags |= FD_REFERENCED;
  2531.         fdInfoPtr->newLinkCount++;
  2532. d1097 1
  2533. a1097 1
  2534.         (newFDInfoPtr->flags & IS_A_DIRECTORY)) {
  2535. d1108 2
  2536. a1109 2
  2537.             fprintf(stderr,
  2538.               "Unable to fetch file descriptor for directory <%d>.",
  2539. d1117 1
  2540. a1117 1
  2541.         }
  2542. a1118 1
  2543.  
  2544. d1145 2
  2545. a1146 1
  2546. CheckDirEntry(dirIndexPtr, dirEntryPtr)
  2547. d1155 1
  2548. d1174 1
  2549. a1174 1
  2550.     fprintf(stderr,
  2551. d1178 1
  2552. d1198 1
  2553. a1198 1
  2554.         fprintf(stderr,"Name length wrong for directory entry: %s.\n", buf);
  2555. d1200 1
  2556. d1217 1
  2557. a1217 1
  2558.         fprintf(stderr,
  2559. d1221 1
  2560. d1230 1
  2561. a1230 1
  2562.     fprintf(stderr, 
  2563. d1234 1
  2564. d1237 5
  2565. d1243 6
  2566. a1248 4
  2567.                !(descInfoArray[dirEntryPtr->fileNumber].flags & FD_ALLOCATED)) {
  2568.     fprintf(stderr, 
  2569.         "File %s%s references non-allocated descriptor.  File Deleted.\n",
  2570.         pathName, dirEntryPtr->fileName);
  2571. d1250 1
  2572. d1254 3
  2573. d1290 1
  2574. a1290 1
  2575.     fprintf(stderr, "SetDotDot: Could not open dir\n");
  2576. d1299 1
  2577. a1299 1
  2578.     fprintf(stderr, "SetDotDot: Could not move from . to ..\n");
  2579. d1303 1
  2580. a1303 1
  2581.     dirFDPtr->numLinks++;
  2582. d1310 1
  2583. a1310 1
  2584.         fprintf(stderr, "SetDotDot: Write failed block %d\n",
  2585. d1325 1
  2586. a1325 2
  2587.  *    Add the file descriptor to a directory.  Its name is taken
  2588.  *    to be its file number.
  2589. d1337 1
  2590. a1337 1
  2591.     fdInfoPtr)
  2592. d1343 1
  2593. a1345 1
  2594.     char         fileName[100];
  2595. a1353 1
  2596.     sprintf(fileName, "%d", fileNumber);
  2597. d1378 2
  2598. a1379 2
  2599.         fprintf(stderr,
  2600.       "Unable to fetch file descriptor for file <%d> to add to directory <%d>",
  2601. d1400 1
  2602. a1400 2
  2603.         dirEntryPtr = 
  2604.             (FsDirEntry *) ((int) dirEntryPtr + recordLength);
  2605. d1411 1
  2606. a1411 1
  2607.     fprintf(stderr, "Directory #%d full.  Couldn't insert %d\n", dirNumber,
  2608. d1414 16
  2609. a1429 1
  2610.  
  2611. d1431 5
  2612. a1435 1
  2613. MakeLostAndFound()
  2614. d1437 3
  2615. a1439 2
  2616.     return(SUCCESS);
  2617. }
  2618. d1441 41
  2619. a1481 4
  2620. ReturnStatus
  2621. MakeRoot()
  2622. {
  2623.     return(SUCCESS);
  2624. @
  2625.  
  2626.  
  2627. 1.18
  2628. log
  2629. @Changed it to print much less about errors unless verbose is on.
  2630. @
  2631. text
  2632. @d11 1
  2633. a11 1
  2634. static char rcsid[] = "$Header: checkdir.c,v 1.17 88/07/19 11:47:29 douglis Exp $ SPRITE (Berkeley)";
  2635. a13 1
  2636. #include "sprite.h"
  2637. a14 1
  2638. #include "io.h"
  2639. d16 1
  2640. a16 4
  2641. #include "checkFS.h"
  2642. #include "mem.h"
  2643. #include "string.h"
  2644. #include "byte.h"
  2645. d18 3
  2646. a20 1
  2647. #include "char.h"
  2648. d22 2
  2649. a23 2
  2650. static    Boolean        adding = FALSE;
  2651. extern    Boolean     writeDisk;
  2652. d29 1
  2653. a29 1
  2654. extern    Boolean        patchRoot;
  2655. d38 1
  2656. a38 1
  2657. extern Boolean verbose;
  2658. d49 2
  2659. a50 1
  2660.  *    SUCCESS, or FAILURE if the descriptor was unreadable.
  2661. d57 1
  2662. a57 1
  2663. ReturnStatus
  2664. d59 2
  2665. a60 2
  2666.     int            fdNum;
  2667.     FsFileDescriptor    **fdPtrPtr;
  2668. d72 1
  2669. a72 1
  2670.     return(FAILURE);
  2671. d78 1
  2672. a78 1
  2673.         return(SUCCESS);
  2674. d81 2
  2675. a82 1
  2676.     Sys_Panic(SYS_FATAL, "FetchFileDesc: FD not found in relocate list.\n");
  2677. d88 1
  2678. a88 1
  2679.         return(SUCCESS);
  2680. d91 2
  2681. a92 1
  2682.     Sys_Panic(SYS_FATAL, "FetchFileDesc: FD not found in mod list.\n");
  2683. d97 4
  2684. a100 5
  2685.     status = BlockRead(partFID, domainPtr, blockNum, 1, (Address) block);
  2686.     if (status != SUCCESS) {
  2687.     Stat_PrintMsg(status,
  2688.               "FetchFileDesc: Read failed on previously readable block");
  2689.     Proc_Exit(EXIT_HARD_ERR);
  2690. d102 4
  2691. a105 4
  2692.     *fdPtrPtr = (FsFileDescriptor *)Mem_Alloc(sizeof(FsFileDescriptor));
  2693.     Byte_Copy(sizeof(FsFileDescriptor), 
  2694.           (Address)&block[offset], (Address)*fdPtrPtr);
  2695.     return(SUCCESS);
  2696. d138 2
  2697. a139 1
  2698.         Sys_Panic(SYS_FATAL, "StoreFileDesc: FD not found in list.\n");
  2699. d144 1
  2700. a144 1
  2701.         modElemPtr = (ModListElement *)Mem_Alloc(sizeof(ModListElement));
  2702. d146 2
  2703. a147 2
  2704.         Byte_Copy(sizeof(FsFileDescriptor), (Address)fdPtr,
  2705.                 (Address)&modElemPtr->fd);
  2706. d149 1
  2707. a149 1
  2708.         Mem_Free((Address)fdPtr);
  2709. d170 1
  2710. a170 1
  2711. static ReturnStatus
  2712. d193 1
  2713. a193 1
  2714.         return(SUCCESS);
  2715. d195 1
  2716. a195 1
  2717.     status = FragRead(partFID, domainPtr,
  2718. d197 4
  2719. a200 6
  2720.               indexInfoPtr->firstBlock);
  2721.     if (status != SUCCESS) {
  2722.         Io_PrintStream(io_StdErr,
  2723.                "MakePtrAccessible: Read (1) failed <%x> block %d\n",
  2724.                status, *blockAddrPtr);
  2725.         return(status);
  2726. d202 1
  2727. a202 1
  2728.     indexInfoPtr->firstBlockNil = FALSE;
  2729. d208 1
  2730. a208 1
  2731.     return(SUCCESS);
  2732. d215 1
  2733. a215 1
  2734.     status = FragRead(partFID, domainPtr,
  2735. d217 4
  2736. a220 6
  2737.               indexInfoPtr->secondBlock);
  2738.     if (status != SUCCESS) {
  2739.         Io_PrintStream(io_StdErr,
  2740.                "MakePtrAccessible: Read (2) failed <%x> block %d\n",
  2741.                status, *blockAddrPtr);
  2742.         return(status);
  2743. d222 1
  2744. a222 1
  2745.     indexInfoPtr->secondBlockNil = FALSE;
  2746. d226 1
  2747. a226 1
  2748.     return(SUCCESS);
  2749. d239 1
  2750. a239 1
  2751.  *    None.
  2752. d246 1
  2753. a246 1
  2754. static ReturnStatus
  2755. d254 2
  2756. a255 2
  2757.     indexInfoPtr->firstBlockNil = TRUE;
  2758.     indexInfoPtr->secondBlockNil = TRUE;
  2759. d257 1
  2760. a257 1
  2761.     indexInfoPtr->dirDirty = FALSE;
  2762. d268 1
  2763. a268 1
  2764.     return(SUCCESS);
  2765. d316 1
  2766. a316 1
  2767. static ReturnStatus
  2768. d320 1
  2769. a320 1
  2770.     Boolean            accessible = FALSE;
  2771. d326 1
  2772. a326 1
  2773.     indexInfoPtr->dirDirty = FALSE;
  2774. d341 1
  2775. a341 1
  2776.         accessible = TRUE;
  2777. d359 1
  2778. a359 1
  2779.         accessible = TRUE;
  2780. d371 1
  2781. a371 1
  2782.         indexInfoPtr->firstBlockNil = TRUE;
  2783. d379 1
  2784. a379 1
  2785.         indexInfoPtr->secondBlockNil = TRUE;
  2786. d383 1
  2787. a383 1
  2788.         accessible = TRUE;
  2789. d394 1
  2790. a394 1
  2791.     return(SUCCESS);
  2792. a424 1
  2793.     ReturnStatus    status;
  2794. d434 1
  2795. a434 1
  2796.     Io_PrintStream(io_StdErr,
  2797. d436 1
  2798. a436 1
  2799.     foundError = TRUE;
  2800. d446 2
  2801. a447 4
  2802.     status = GetFirstIndex(0, indexInfoPtr);
  2803.     if (status != SUCCESS) {
  2804.     Io_PrintStream(io_StdErr, "OpenDir: Error setting up index <%x>\n",
  2805.                status);
  2806. d460 1
  2807. a460 1
  2808.     status = FragRead(partFID, domainPtr,
  2809. d463 3
  2810. a465 4
  2811.               fragsToRead, indexInfoPtr->dirBlock);
  2812.     if (status != SUCCESS) {
  2813.     Io_PrintStream(io_StdErr, "OpenDir: Read failed <%x> block %d\n",
  2814.                status, indexInfoPtr->blockAddr + 
  2815. a495 1
  2816.     ReturnStatus    status;
  2817. d513 1
  2818. a513 1
  2819.         status = FragWrite(partFID, domainPtr,
  2820. d517 4
  2821. a520 5
  2822.                   indexInfoPtr->numFrags, indexInfoPtr->dirBlock);
  2823.         if (status != SUCCESS) {
  2824.         Io_PrintStream(io_StdErr, 
  2825.                "NextDirEntry: Write failed <%x> block %d\n",
  2826.                    status, indexInfoPtr->blockAddr + 
  2827. d539 1
  2828. a539 1
  2829.         status = FragWrite(partFID, domainPtr,
  2830. d543 4
  2831. a546 5
  2832.                   indexInfoPtr->numFrags, indexInfoPtr->dirBlock);
  2833.         if (status != SUCCESS) {
  2834.         Io_PrintStream(io_StdErr, 
  2835.                "NextDirEntry: Write (2) failed <%x> block %d\n",
  2836.                    status, indexInfoPtr->blockAddr + 
  2837. d552 2
  2838. a553 4
  2839.     status = GetNextIndex(indexInfoPtr);
  2840.     if (status != SUCCESS) {
  2841.         Io_PrintStream(io_StdErr, 
  2842.                "NextDirEntry: Get index failed <%x>\n", status);
  2843. d564 1
  2844. a564 1
  2845.     status = FragRead(partFID, domainPtr,
  2846. d568 3
  2847. a570 5
  2848.               fragsToRead, indexInfoPtr->dirBlock);
  2849.     if (status != SUCCESS) {
  2850.         Io_PrintStream(io_StdErr, 
  2851.                "NextDirEntry: Read failed <%x> block %d\n",
  2852.                status, indexInfoPtr->blockAddr + 
  2853. a616 1
  2854.     ReturnStatus     status;
  2855. d632 3
  2856. a634 2
  2857.     if (FetchFileDesc(FS_ROOT_FILE_NUMBER, &rootFDPtr) != SUCCESS) {
  2858.     Sys_Panic(SYS_FATAL, "Unable to fetch file descriptor for root");
  2859. d640 1
  2860. a640 1
  2861.     Io_PrintStream(io_StdErr, "Root directory corrupted\n");
  2862. d642 1
  2863. a642 1
  2864.         Proc_Exit(EXIT_HARD_ERR);
  2865. d644 2
  2866. a645 2
  2867.         Io_PrintStream(io_StdErr, "Can't fix empty root (can you?)\n");
  2868.         Proc_Exit(EXIT_HARD_ERR);
  2869. d653 1
  2870. a653 1
  2871.     Io_PrintStream(io_StdErr, "Attempting to re-create the root\n");
  2872. d660 1
  2873. a660 1
  2874.         Proc_Exit(EXIT_HARD_ERR);
  2875. d666 1
  2876. a666 1
  2877.     (void)String_Copy("/", pathName);
  2878. d672 2
  2879. a673 2
  2880.         if (String_NCompare(dirEntryPtr->nameLength, 
  2881.                 "lost+found", dirEntryPtr->fileName) == 0) {
  2882. d681 1
  2883. a681 1
  2884.     Io_PrintStream(io_StdErr, "lost+found missing from root\n");
  2885. d686 3
  2886. a688 3
  2887.     if (FetchFileDesc(lostFoundFileNum, &lostFoundFDPtr) != SUCCESS) {
  2888.         Sys_Panic(SYS_FATAL,
  2889.               "Unable to fetch file descriptor for lost+found");
  2890. d691 1
  2891. a691 1
  2892.     (void)String_Copy("/lost+found/", pathName);
  2893. d694 1
  2894. a694 1
  2895.         Io_PrintStream(io_StdErr,
  2896. d698 1
  2897. a698 1
  2898.         Boolean    dirOK;
  2899. d706 1
  2900. a706 1
  2901.             Io_PrintStream(io_StdErr, "Could not open lost+found\n");
  2902. d722 1
  2903. a722 1
  2904.     Boolean            dirOK;
  2905. d731 3
  2906. a733 3
  2907.     if (FetchFileDesc(i, &newFDPtr) != SUCCESS) {
  2908.         Sys_Panic(SYS_WARNING,
  2909.               "Unable to fetch file descriptor for directory <%d>", i);
  2910. d752 1
  2911. a752 1
  2912.     rootDirEntryPtr->nameLength = String_Length(fileName);
  2913. d755 1
  2914. a755 1
  2915.     (void)String_Copy(fileName, rootDirEntryPtr->fileName);
  2916. d760 1
  2917. a760 1
  2918.     rootDirEntryPtr->nameLength = String_Length(fileName);
  2919. d763 1
  2920. a763 1
  2921.     (void)String_Copy(fileName, rootDirEntryPtr->fileName);
  2922. d785 1
  2923. a785 1
  2924.         status = FragWrite(partFID, domainPtr,
  2925. d787 4
  2926. a790 5
  2927.                     FS_FRAGMENTS_PER_BLOCK,
  2928.                 rootDirIndex.numFrags, rootDirIndex.dirBlock);
  2929.         if (status != SUCCESS) {
  2930.         Stat_PrintMsg(status, "CheckDirTree: Write failed");
  2931.         Proc_Exit(EXIT_HARD_ERR);
  2932. d811 1
  2933. a811 1
  2934.         Io_PrintStream(io_StdErr, "File %d is unreferenced\n", i);
  2935. d814 2
  2936. a815 2
  2937.         foundError = TRUE;
  2938.         Io_Flush(io_StdErr);
  2939. d822 1
  2940. a822 1
  2941.         Io_PrintStream(io_StdErr,
  2942. d827 2
  2943. a828 2
  2944.         foundError = TRUE;
  2945.         Io_Flush(io_StdErr);
  2946. d837 3
  2947. a839 3
  2948.         if (FetchFileDesc(i, &fdPtr) != SUCCESS) {
  2949.             Sys_Panic(SYS_WARNING,
  2950.                   "Unable to fetch file descriptor for file <%d> to update link count", i);
  2951. d849 1
  2952. a849 1
  2953.     Io_PrintStream(io_StdErr, "%d unreferenced files\n", unrefFiles);
  2954. d852 2
  2955. a853 1
  2956.     Io_PrintStream(io_StdErr, "%d links counts corrected\n", unrefFiles);
  2957. d857 2
  2958. a858 2
  2959.     status = FragWrite(partFID, domainPtr,
  2960.                 lostDirIndex.blockAddr + domainPtr->dataOffset * 
  2961. d860 4
  2962. a863 4
  2963.                 lostDirIndex.numFrags, lostDirIndex.dirBlock);
  2964.     if (status != SUCCESS) {
  2965.         Stat_PrintMsg(status, "CheckDirTree: Write failed");
  2966.         Proc_Exit(EXIT_HARD_ERR);
  2967. d902 1
  2968. a902 1
  2969.     int            *dirOKPtr;    /* Return TRUE if the directory is
  2970. d912 1
  2971. a912 1
  2972.     *dirOKPtr = FALSE;
  2973. d918 1
  2974. a918 1
  2975.     nullIndex = String_Length(pathName);
  2976. d920 1
  2977. a920 1
  2978.     Io_PrintStream(io_StdErr, "Empty directory %d %s changed to a file.\n",
  2979. d922 1
  2980. a922 1
  2981.     foundError = TRUE;
  2982. d939 3
  2983. a941 3
  2984.         String_NCompare(dirEntryPtr->nameLength, ".", 
  2985.                 dirEntryPtr->fileName) != 0) {
  2986.         Io_PrintStream(io_StdErr,
  2987. d944 1
  2988. a944 1
  2989.         foundError = TRUE;
  2990. d951 1
  2991. a951 1
  2992.         Io_PrintStream(io_StdErr, 
  2993. d954 1
  2994. a954 1
  2995.         foundError = TRUE;
  2996. d956 1
  2997. a956 1
  2998.         dirIndex.dirDirty = TRUE;
  2999. d964 3
  3000. a966 3
  3001.         String_NCompare(dirEntryPtr->nameLength, "..", 
  3002.                 dirEntryPtr->fileName) != 0) {
  3003.         Io_PrintStream(io_StdErr,
  3004. d969 1
  3005. a969 1
  3006.         foundError = TRUE;
  3007. d981 2
  3008. a982 1
  3009.         DirList *dirListPtr = Mem_New(DirList);
  3010. d984 1
  3011. a984 1
  3012.         Io_PrintStream(io_StdErr, "Found #%d, an orphan of dir #%d\n", 
  3013. d997 1
  3014. a997 1
  3015.         Boolean    dirOK;
  3016. d1003 5
  3017. a1007 7
  3018.         (void)String_NCat(dirEntryPtr->nameLength,
  3019.                   dirEntryPtr->fileName,
  3020.                pathName);
  3021.         (void)String_Cat("/", pathName);
  3022.         if (FetchFileDesc(dirEntryPtr->fileNumber, &newFDPtr) !=
  3023.             SUCCESS) {
  3024.             Sys_Panic(SYS_WARNING,
  3025. d1023 1
  3026. a1023 1
  3027.     *dirOKPtr = TRUE;
  3028. d1072 1
  3029. a1072 1
  3030.     Io_PrintStream(io_StdErr,
  3031. d1075 1
  3032. a1075 1
  3033.     foundError = TRUE;
  3034. d1082 1
  3035. a1082 1
  3036.     dirIndexPtr->dirDirty = TRUE;
  3037. d1089 3
  3038. a1091 4
  3039.     Boolean    nameError = FALSE;
  3040.     nameLength = 
  3041.         String_NLength(dirEntryPtr->recordLength - FS_DIR_ENTRY_HEADER, 
  3042.                    dirEntryPtr->fileName);
  3043. d1093 1
  3044. a1093 1
  3045.         Byte_Copy(nameLength, dirEntryPtr->fileName, buf);
  3046. d1095 2
  3047. a1096 3
  3048.         Io_PrintStream(io_StdErr,
  3049.             "Name length wrong for directory entry: %s.\n", buf);
  3050.         foundError = TRUE;
  3051. d1098 1
  3052. a1098 1
  3053.         dirIndexPtr->dirDirty = TRUE;
  3054. d1105 1
  3055. a1105 1
  3056.         if (*strPtr < 0 || !Char_IsPrint(*strPtr)) {
  3057. d1107 1
  3058. a1107 1
  3059.         nameError = TRUE;
  3060. d1112 2
  3061. a1113 2
  3062.         dirIndexPtr->dirDirty = TRUE;
  3063.         Io_PrintStream(io_StdErr,
  3064. d1116 1
  3065. a1116 1
  3066.         foundError = TRUE;
  3067. d1125 1
  3068. a1125 1
  3069.     Io_PrintStream(io_StdErr, 
  3070. d1128 1
  3071. a1128 1
  3072.     foundError = TRUE;
  3073. d1130 1
  3074. a1130 1
  3075.     dirIndexPtr->dirDirty = TRUE;
  3076. d1133 1
  3077. a1133 1
  3078.     Io_PrintStream(io_StdErr, 
  3079. d1136 1
  3080. a1136 1
  3081.     foundError = TRUE;
  3082. d1138 1
  3083. a1138 1
  3084.     dirIndexPtr->dirDirty = TRUE;
  3085. d1158 1
  3086. a1158 1
  3087. static Boolean
  3088. a1164 1
  3089.     ReturnStatus     status;
  3090. d1173 2
  3091. a1174 2
  3092.     Io_PrintStream(io_StdErr, "SetDotDot: Could not open dir\n");
  3093.     return(FALSE);
  3094. d1182 2
  3095. a1183 2
  3096.     Io_PrintStream(io_StdErr, "SetDotDot: Could not move from . to ..\n");
  3097.     return(FALSE);
  3098. d1190 1
  3099. a1190 1
  3100.     status = FragWrite(partFID, domainPtr, 
  3101. d1192 3
  3102. a1194 4
  3103.        dirIndex.numFrags, dirIndex.dirBlock);
  3104.     if (status != SUCCESS) {
  3105.         Io_PrintStream(io_StdErr, "SetDotDot: Write failed <%x> block %d\n",
  3106.         status, dirIndex.blockAddr + 
  3107. d1196 1
  3108. a1196 1
  3109.         return(FALSE);
  3110. d1199 1
  3111. a1199 1
  3112.     return(TRUE);
  3113. d1237 3
  3114. a1239 3
  3115.     adding = TRUE;
  3116.     Io_PrintString(fileName, "%d", fileNumber);
  3117.     nameLength = String_Length(fileName);
  3118. d1262 3
  3119. a1264 3
  3120.     if (FetchFileDesc(fileNumber, &fdPtr) != SUCCESS) {
  3121.         Sys_Panic(SYS_WARNING,
  3122.               "Unable to fetch file descriptor for file <%d> to add to directory <%d>",
  3123. d1280 2
  3124. a1281 2
  3125.     dirIndexPtr->dirDirty = TRUE;
  3126.     (void)String_Copy(fileName, dirEntryPtr->fileName);
  3127. d1297 1
  3128. a1297 2
  3129.     Io_PrintStream(io_StdErr, 
  3130.            "Directory #%d full.  Couldn't insert %d\n", dirNumber,
  3131. d1311 30
  3132. @
  3133.  
  3134.  
  3135. 1.17
  3136. log
  3137. @Added ability to salvage and relocate file descriptors in unreadable
  3138. blocks and to mark those blocks as unuseable (temporarily -- if readable
  3139. again later, they will be reclaimed).
  3140. @
  3141. text
  3142. @d11 1
  3143. a11 1
  3144. static char rcsid[] = "$Header: checkdir.c,v 1.16 88/06/02 12:59:45 brent Exp $ SPRITE (Berkeley)";
  3145. d41 2
  3146. d439 2
  3147. a440 1
  3148.     Io_PrintStream(io_StdErr, "Directory not multiple of directory block size. Directory corrected.\n");
  3149. d638 2
  3150. d818 1
  3151. d826 4
  3152. a829 1
  3153.         Io_PrintStream(io_StdErr, "File %d is unreferenced\n", i);
  3154. d837 6
  3155. a842 2
  3156.         Io_PrintStream(io_StdErr, "Link count corrected for file %d.  Is %d should be %d.\n", 
  3157.         i, fdInfoPtr->origLinkCount, fdInfoPtr->newLinkCount);
  3158. d864 6
  3159. d956 2
  3160. a957 1
  3161.         Io_PrintStream(io_StdErr, ". missing in directory %d %s.  Changed to a file.\n",
  3162. d981 2
  3163. a982 1
  3164.         Io_PrintStream(io_StdErr, ".. missing in directory %d %s.  Changed to a file.\n",
  3165. d1024 1
  3166. a1024 1
  3167.                   "Unable to fetch file descriptor for directory <%d>.",
  3168. d1088 3
  3169. a1090 1
  3170.     Io_PrintStream(io_StdErr, "Bad record length in directory.  Directory entry deleted from %s\n", pathName);
  3171. d1112 2
  3172. a1113 1
  3173.         Io_PrintStream(io_StdErr, "Name length wrong for directory entry: %s.\n", buf);
  3174. d1143 3
  3175. a1145 1
  3176.     Io_PrintStream(io_StdErr, "Bad file number in directory.  Directory entry deleted from %s.\n", pathName);
  3177. d1152 1
  3178. a1152 1
  3179.         "File %s%s references non-allocated descriptor.  File Deleted\n",
  3180. @
  3181.  
  3182.  
  3183. 1.16
  3184. log
  3185. @Added code to rebuild a trashed root directory
  3186. @
  3187. text
  3188. @d11 1
  3189. a11 1
  3190. static char rcsid[] = "$Header: checkdir.c,v 1.15 87/11/13 13:04:36 nelson Exp $ SPRITE (Berkeley)";
  3191. d50 1
  3192. a50 1
  3193.  *    None.
  3194. d57 1
  3195. a57 1
  3196. void
  3197. d63 1
  3198. d71 12
  3199. d87 1
  3200. a87 1
  3201.         return;
  3202. d90 1
  3203. a90 1
  3204.     Sys_Panic(SYS_FATAL, "FetchFileDesc: FD not found in list.\n");
  3205. d97 2
  3206. a98 1
  3207.     Stat_PrintMsg(status, "FetchFileDesc: Read failed");
  3208. d104 1
  3209. d643 3
  3210. a645 1
  3211.     FetchFileDesc(FS_ROOT_FILE_NUMBER, &rootFDPtr);
  3212. d676 1
  3213. a676 1
  3214.     String_Copy("/", pathName);
  3215. d696 4
  3216. a699 1
  3217.     FetchFileDesc(lostFoundFileNum, &lostFoundFDPtr);
  3218. d701 1
  3219. a701 1
  3220.     String_Copy("/lost+found/", pathName);
  3221. d741 5
  3222. a745 1
  3223.     FetchFileDesc(i, &newFDPtr);
  3224. d765 1
  3225. a765 1
  3226.     String_Copy(fileName, rootDirEntryPtr->fileName);
  3227. d773 1
  3228. a773 1
  3229.     String_Copy(fileName, rootDirEntryPtr->fileName);
  3230. d814 1
  3231. d840 8
  3232. a847 4
  3233.         FetchFileDesc(i, &fdPtr);
  3234.         fdPtr->numLinks = fdInfoPtr->newLinkCount;
  3235.         fdInfoPtr->flags |= FD_MODIFIED;
  3236.         StoreFileDesc(i, fdPtr);
  3237. d996 2
  3238. a997 1
  3239.         String_NCat(dirEntryPtr->nameLength, dirEntryPtr->fileName,
  3240. d999 12
  3241. a1010 6
  3242.         String_Cat("/", pathName);
  3243.         FetchFileDesc(dirEntryPtr->fileNumber, &newFDPtr);
  3244.         CheckDir(dirEntryPtr->fileNumber, newFDPtr, 
  3245.                   newFDInfoPtr, lostDirNum, &dirOK);
  3246.         pathName[nullIndex] = '\0';
  3247.         StoreFileDesc(dirEntryPtr->fileNumber, newFDPtr);
  3248. d1256 6
  3249. a1261 1
  3250.     FetchFileDesc(fileNumber, &fdPtr);
  3251. d1275 1
  3252. a1275 1
  3253.     String_Copy(fileName, dirEntryPtr->fileName);
  3254. @
  3255.  
  3256.  
  3257. 1.15
  3258. log
  3259. @Can handle read and write errors and continue.
  3260. @
  3261. text
  3262. @d11 1
  3263. a11 1
  3264. static char rcsid[] = "$Header: checkdir.c,v 1.14 87/10/21 11:03:56 nelson Exp $ SPRITE (Berkeley)";
  3265. d17 1
  3266. a17 1
  3267. #include "fsDisk.h"
  3268. d22 1
  3269. d32 1
  3270. d36 1
  3271. a36 1
  3272. void    AddToLostAndFound();
  3273. d85 1
  3274. a85 1
  3275.     Proc_Exit(status);
  3276. d582 9
  3277. d619 1
  3278. d634 6
  3279. a639 1
  3280.     Proc_Exit(1);
  3281. d641 4
  3282. a644 10
  3283.     MakeRoot(descInfo);
  3284.     */
  3285.     }
  3286.     OpenDir(rootFDPtr, &descInfoArray[FS_ROOT_FILE_NUMBER], &dirIndex, 
  3287.         &dirEntryPtr);
  3288.  
  3289.     String_Copy("/", pathName);
  3290.     while (dirEntryPtr != (FsDirEntry *) NULL) {
  3291.     /*
  3292.      * Go through the root directory checking each directory entry.
  3293. d646 8
  3294. a653 4
  3295.     CheckDirEntry(&dirIndex, dirEntryPtr);
  3296.     if (String_NCompare(dirEntryPtr->nameLength, 
  3297.                 "lost+found", dirEntryPtr->fileName) == 0) {
  3298.         lostFoundFileNum = dirEntryPtr->fileNumber;
  3299. d655 16
  3300. a670 1
  3301.     NextDirEntry(&dirIndex, &dirEntryPtr);
  3302. d677 1
  3303. a677 1
  3304.      * Now that the root is ok, make sure that lost and found is consistent.
  3305. d690 2
  3306. a691 1
  3307.         CheckDir(lostFoundFileNum, lostFoundFDPtr, fdInfoPtr, &dirOK);
  3308. d706 2
  3309. a707 1
  3310.      * Check all file descriptors.
  3311. d722 1
  3312. a722 1
  3313.     CheckDir(i, newFDPtr, fdInfoPtr, &dirOK);
  3314. d726 55
  3315. d799 2
  3316. a800 1
  3317.         AddToLostAndFound(i, fdInfoPtr);
  3318. d830 1
  3319. a830 1
  3320.         Proc_Exit(status);
  3321. d858 1
  3322. a858 1
  3323. CheckDir(fdNum, fdPtr, fdInfoPtr, dirOKPtr)
  3324. d865 4
  3325. d941 14
  3326. d972 1
  3327. a972 1
  3328.                   newFDInfoPtr, &dirOK);
  3329. d1104 1
  3330. a1104 1
  3331.  *    Make ".." in the given directory point to lost and found.
  3332. d1115 3
  3333. a1117 1
  3334. SetDotDot(fdPtr, fdInfoPtr)
  3335. d1143 3
  3336. a1145 3
  3337.     lostFoundFDPtr->numLinks++;
  3338.     descInfoArray[lostFoundFileNum].flags |= FD_MODIFIED;
  3339.     dirEntryPtr->fileNumber = lostFoundFileNum;
  3340. d1164 1
  3341. a1164 1
  3342.  * AddToLostAndFound --
  3343. d1166 2
  3344. a1167 1
  3345.  *    Add the file descriptor to the lost and found directory.
  3346. d1173 1
  3347. a1173 1
  3348.  *    The lost and found directory may be modified.
  3349. d1178 6
  3350. a1183 1
  3351. AddToLostAndFound(fileNumber, fdInfoPtr)
  3352. d1192 1
  3353. d1200 5
  3354. a1204 4
  3355.     while (lostDirEntryPtr != (FsDirEntry *) NULL) {
  3356.     if (lostDirEntryPtr->fileNumber != 0) {
  3357.         oldRecLength = FsDirRecLength(lostDirEntryPtr->nameLength);
  3358.         leftOver = lostDirEntryPtr->recordLength - oldRecLength;
  3359. d1206 5
  3360. a1210 5
  3361.         lostDirEntryPtr->recordLength = oldRecLength;
  3362.         lostDirEntryPtr = 
  3363.             (FsDirEntry *) ((int) lostDirEntryPtr + oldRecLength);
  3364.         lostDirEntryPtr->recordLength = leftOver;
  3365.         lostDirIndex.dirOffset += oldRecLength;
  3366. d1212 1
  3367. a1212 1
  3368.         NextDirEntry(&lostDirIndex, &lostDirEntryPtr);
  3369. d1215 2
  3370. a1216 2
  3371.     } else if (lostDirEntryPtr->recordLength < recordLength) {
  3372.         NextDirEntry(&lostDirIndex, &lostDirEntryPtr);
  3373. d1222 2
  3374. a1223 1
  3375.         if (!SetDotDot(fdPtr, fdInfoPtr)) {
  3376. d1231 5
  3377. a1235 5
  3378.     lostDirEntryPtr->fileNumber = fileNumber;
  3379.     lostDirEntryPtr->nameLength = nameLength;
  3380.     lostDirIndex.dirDirty = TRUE;
  3381.     String_Copy(fileName, lostDirEntryPtr->fileName);
  3382.     leftOver = lostDirEntryPtr->recordLength - recordLength;
  3383. d1237 6
  3384. a1242 6
  3385.         lostDirEntryPtr->recordLength = recordLength;
  3386.         lostDirEntryPtr = 
  3387.             (FsDirEntry *) ((int) lostDirEntryPtr + recordLength);
  3388.         lostDirEntryPtr->fileNumber = 0;
  3389.         lostDirEntryPtr->recordLength = leftOver;
  3390.         lostDirIndex.dirOffset += recordLength;
  3391. d1244 1
  3392. a1244 1
  3393.         NextDirEntry(&lostDirIndex, &lostDirEntryPtr);
  3394. d1246 1
  3395. d1251 1
  3396. a1251 1
  3397.            "Lost and found directory full.  Couldn't insert %d\n", 
  3398. @
  3399.  
  3400.  
  3401. 1.14
  3402. log
  3403. @Set error status flag on error.
  3404. @
  3405. text
  3406. @d11 1
  3407. a11 1
  3408. static char rcsid[] = "$Header: checkdir.c,v 1.13 87/10/21 10:38:20 nelson Exp $ SPRITE (Berkeley)";
  3409. a111 3
  3410.     char        block[FS_BLOCK_SIZE];
  3411.     int            blockNum;
  3412.     int            offset;
  3413. d151 1
  3414. a151 1
  3415. static void
  3416. d174 1
  3417. a174 1
  3418.         return;
  3419. d180 4
  3420. a183 2
  3421.         Stat_PrintMsg(status, "MakePtrAccessible: Read failed (1)");
  3422.         Proc_Exit(status);
  3423. d191 1
  3424. a191 1
  3425.     return;
  3426. d202 4
  3427. a205 2
  3428.         Stat_PrintMsg(status, "MakePtrAccessible: Read failed (2)");
  3429.         Proc_Exit(status);
  3430. d211 1
  3431. d231 1
  3432. a231 1
  3433. static void
  3434. d253 1
  3435. a253 1
  3436.     return;
  3437. d281 1
  3438. a281 1
  3439.     MakePtrAccessible(indexInfoPtr);
  3440. d301 1
  3441. a301 1
  3442. static void
  3443. d377 3
  3444. a379 1
  3445.     MakePtrAccessible(indexInfoPtr);
  3446. d431 7
  3447. a437 1
  3448.     GetFirstIndex(0, indexInfoPtr);
  3449. d452 5
  3450. a456 2
  3451.     Stat_PrintMsg(status, "OpenDir: Read failed");
  3452.     Proc_Exit(status);
  3453. a478 1
  3454.  
  3455. d508 4
  3456. a511 2
  3457.         Stat_PrintMsg(status, "NextDirEntry: Write failed");
  3458.         Proc_Exit(status);
  3459. d535 6
  3460. a540 2
  3461.         Stat_PrintMsg(status, "NextDirEntry: Write failed (2)");
  3462.         Proc_Exit(status);
  3463. d543 7
  3464. a549 1
  3465.     GetNextIndex(indexInfoPtr);
  3466. d563 6
  3467. a568 2
  3468.         Stat_PrintMsg(status, "NextDirEntry: Read failed");
  3469.         Proc_Exit(status);
  3470. d627 2
  3471. a628 1
  3472.     OpenDir(rootFDPtr, fdInfoPtr, &dirIndex, &dirEntryPtr);
  3473. d664 4
  3474. d1008 1
  3475. a1008 1
  3476. static void
  3477. d1021 4
  3478. d1030 4
  3479. d1043 4
  3480. a1046 2
  3481.         Stat_PrintMsg(status, "SetDotDot: Write failed");
  3482.         Proc_Exit(status);
  3483. d1049 1
  3484. d1106 3
  3485. a1108 1
  3486.         SetDotDot(fdPtr, fdInfoPtr);
  3487. @
  3488.  
  3489.  
  3490. 1.13
  3491. log
  3492. @Added ability to handle the bad block file.
  3493. @
  3494. text
  3495. @d11 1
  3496. a11 1
  3497. static char rcsid[] = "$Header: checkdir.c,v 1.12 87/10/05 12:51:50 nelson Exp $ SPRITE (Berkeley)";
  3498. d417 1
  3499. d676 1
  3500. d684 1
  3501. d764 1
  3502. d785 1
  3503. d795 1
  3504. d809 1
  3505. d893 1
  3506. d915 1
  3507. d935 1
  3508. d945 1
  3509. d953 1
  3510. @
  3511.  
  3512.  
  3513. 1.12
  3514. log
  3515. @Checks for file in a directory that references a non-allocated descriptor.
  3516. @
  3517. text
  3518. @d11 1
  3519. a11 1
  3520. static char rcsid[] = "$Header: checkdir.c,v 1.11 87/09/10 14:40:39 nelson Exp $ SPRITE (Berkeley)";
  3521. d668 2
  3522. a669 1
  3523.     if (!(fdInfoPtr->flags & FD_ALLOCATED)) {
  3524. @
  3525.  
  3526.  
  3527. 1.11
  3528. log
  3529. @Checks for and fixes names in directories that have non-printable
  3530. characters.
  3531. @
  3532. text
  3533. @d11 1
  3534. a11 1
  3535. static char rcsid[] = "$Header: checkdir.c,v 1.10 87/08/10 10:48:29 nelson Exp $ SPRITE (Berkeley)";
  3536. d936 7
  3537. a942 1
  3538.     return;
  3539. @
  3540.  
  3541.  
  3542. 1.10
  3543. log
  3544. @Changed to use new method that requires much less memory.
  3545. @
  3546. text
  3547. @d11 1
  3548. a11 1
  3549. static char rcsid[] = "$Header: checkdir.c,v 1.9 87/07/14 14:39:27 nelson Exp $ SPRITE (Berkeley)";
  3550. d22 1
  3551. d861 5
  3552. a865 4
  3553.     int        dirBlockOffset;
  3554.     int        lastDirByte;
  3555.     char    buf[FS_MAX_NAME_LENGTH + 1];
  3556.     int        nameLength;
  3557. d898 1
  3558. d908 17
  3559. @
  3560.  
  3561.  
  3562. 1.9
  3563. log
  3564. @Allow lost and found to be anywhere, not just fd 3.  This allows a corrupted
  3565. lost and found directory to be easily recreated.
  3566. @
  3567. text
  3568. @d11 1
  3569. a11 1
  3570. static char rcsid[] = "$Header: checkdir.c,v 1.8 87/07/14 11:32:41 brent Exp $ SPRITE (Berkeley)";
  3571. d32 2
  3572. d35 3
  3573. d42 99
  3574. d153 1
  3575. a153 1
  3576. static ReturnStatus
  3577. d158 1
  3578. a158 1
  3579.     register FsFileDescriptor    *descPtr;
  3580. d161 2
  3581. a162 1
  3582.     descPtr = &(indexInfoPtr->descInfoPtr->fileDesc);
  3583. d166 1
  3584. a166 1
  3585.     *blockAddrPtr = descPtr->indirect[0];
  3586. d168 1
  3587. a168 1
  3588.     *blockAddrPtr = descPtr->indirect[1];
  3589. d176 1
  3590. a176 1
  3591.         return(SUCCESS);
  3592. d182 2
  3593. a183 1
  3594.         return(status);
  3595. d191 1
  3596. a191 1
  3597.     return(SUCCESS);
  3598. d197 8
  3599. a204 9
  3600.     if (*blockAddrPtr == FS_NIL_INDEX) {
  3601.     return(SUCCESS);
  3602.     }
  3603.     status = FragRead(partFID, domainPtr,
  3604.               *blockAddrPtr, FS_FRAGMENTS_PER_BLOCK,
  3605.               indexInfoPtr->secondBlock);
  3606.     if (status != SUCCESS) {
  3607.     return(status);
  3608.     } else {
  3609. a207 1
  3610.     return(SUCCESS);
  3611. d221 1
  3612. a221 2
  3613.  *    A status indicating whether there was sufficient space to allocate
  3614.  *    indirect blocks.
  3615. d228 1
  3616. a228 1
  3617. static ReturnStatus
  3618. d234 1
  3619. a234 1
  3620.     FsFileDescriptor    *descPtr;
  3621. d241 1
  3622. a241 1
  3623.     descPtr = &indexInfoPtr->descInfoPtr->fileDesc;
  3624. d249 2
  3625. a250 2
  3626.     indexInfoPtr->blockAddr = descPtr->direct[blockNum];
  3627.     return(SUCCESS);
  3628. d278 1
  3629. a278 1
  3630.     return(MakePtrAccessible(indexInfoPtr));
  3631. d291 1
  3632. a291 1
  3633.  *    A status indicating whether indirect blocks could be read in.
  3634. d298 1
  3635. a298 1
  3636. static ReturnStatus
  3637. d303 1
  3638. a303 1
  3639.     register FsFileDescriptor    *descPtr;
  3640. d305 1
  3641. a305 1
  3642.     descPtr = &(indexInfoPtr->descInfoPtr->fileDesc);
  3643. d322 1
  3644. a322 1
  3645.                 descPtr->direct[indexInfoPtr->firstIndex];
  3646. d374 1
  3647. a374 3
  3648.     return(MakePtrAccessible(indexInfoPtr));
  3649.     } else {
  3650.     return(SUCCESS);
  3651. d387 1
  3652. a387 1
  3653.  *    A return status.
  3654. d395 6
  3655. a400 3
  3656. static ReturnStatus
  3657. OpenDir(descInfoPtr, indexInfoPtr, dirEntryPtrPtr)
  3658.     FdInfo        *descInfoPtr;    /* Descriptor for the directory. */
  3659. d408 1
  3660. a408 1
  3661.     if (descInfoPtr->fileDesc.lastByte == -1) {
  3662. d413 2
  3663. a414 2
  3664.     return(SUCCESS);
  3665.     } else if ((descInfoPtr->fileDesc.lastByte + 1) % FS_DIR_BLOCK_SIZE != 0) {
  3666. d416 3
  3667. a418 3
  3668.     descInfoPtr->fileDesc.lastByte = 
  3669.         (descInfoPtr->fileDesc.lastByte & ~(FS_DIR_BLOCK_SIZE - 1)) +
  3670.             FS_DIR_BLOCK_SIZE - 1;
  3671. d423 3
  3672. a425 5
  3673.     indexInfoPtr->descInfoPtr = descInfoPtr;
  3674.     status = GetFirstIndex(0, indexInfoPtr);
  3675.     if (status != SUCCESS) {
  3676.     return(status);
  3677.     }
  3678. d429 1
  3679. a429 1
  3680.     if (descInfoPtr->fileDesc.lastByte >= FS_BLOCK_SIZE - 1) {
  3681. d432 1
  3682. a432 1
  3683.     fragsToRead = descInfoPtr->fileDesc.lastByte / FS_FRAGMENT_SIZE + 1;
  3684. d440 5
  3685. a444 6
  3686.     return(status);
  3687.     } else {
  3688.     indexInfoPtr->dirOffset = 0;
  3689.     *dirEntryPtrPtr = (FsDirEntry *) indexInfoPtr->dirBlock;
  3690.     return(SUCCESS);
  3691.     }
  3692. d456 1
  3693. a456 1
  3694.  *    A return status.
  3695. d465 1
  3696. a465 1
  3697. ReturnStatus
  3698. d478 1
  3699. a478 1
  3700.     lastByte = indexInfoPtr->descInfoPtr->fileDesc.lastByte;
  3701. d494 2
  3702. a495 1
  3703.         return(status);
  3704. d498 1
  3705. a498 1
  3706.     return(SUCCESS);
  3707. d519 2
  3708. a520 1
  3709.         return(status);
  3710. d523 1
  3711. a523 4
  3712.     status = GetNextIndex(indexInfoPtr);
  3713.     if (status != SUCCESS) {
  3714.         return(status);
  3715.     }
  3716. d537 2
  3717. a538 4
  3718.         return(status);
  3719.     } else {
  3720.         indexInfoPtr->dirOffset = 0;
  3721.         dirEntryPtr = (FsDirEntry *) indexInfoPtr->dirBlock;
  3722. d540 2
  3723. a544 2
  3724.  
  3725.     return(SUCCESS);
  3726. d567 1
  3727. a567 1
  3728. ReturnStatus
  3729. d575 1
  3730. a575 1
  3731.     register FdInfo    *descInfoPtr;
  3732. d586 5
  3733. a590 4
  3734.     descInfoPtr = &descInfoArray[FS_ROOT_FILE_NUMBER];
  3735.     if (descInfoPtr->fileDesc.flags & FS_FD_FREE ||
  3736.     descInfoPtr->fileDesc.fileType != FS_DIRECTORY ||
  3737.     descInfoPtr->fileDesc.lastByte == -1) {
  3738. d592 1
  3739. a592 1
  3740.     return(FAILURE);
  3741. d597 1
  3742. a597 5
  3743.     status = OpenDir(descInfoPtr, &dirIndex, &dirEntryPtr);
  3744.     if (status != SUCCESS) {
  3745.     Io_PrintStream(io_StdErr, "CheckDirTree: Disk error on root (1) <%x>\n", status);
  3746.     return(status);
  3747.     }
  3748. a604 4
  3749.     if (status != SUCCESS) {
  3750.         Io_PrintStream(io_StdErr, "CheckDirTree: Disk error on root (2) <%x>\n", status);
  3751.         return(status);
  3752.     }
  3753. d609 1
  3754. a609 5
  3755.     status = NextDirEntry(&dirIndex, &dirEntryPtr);
  3756.     if (status != SUCCESS) {
  3757.         Io_PrintStream(io_StdErr, "CheckDirTree: Disk error on root (3) <%x>\n", status);
  3758.         return(status);
  3759.     }
  3760. d618 2
  3761. d621 2
  3762. a622 2
  3763.     descInfoPtr = &descInfoArray[lostFoundFileNum];
  3764.     if (descInfoPtr->fileDesc.fileType != FS_DIRECTORY) {
  3765. d629 4
  3766. a632 14
  3767.         status = CheckDir(lostFoundFileNum, descInfoPtr, &dirOK);
  3768.         if (status == SUCCESS) {
  3769.         if (dirOK) {
  3770.             status = OpenDir(descInfoPtr, &lostDirIndex,
  3771.                      &lostDirEntryPtr);
  3772.             if (status != SUCCESS) {
  3773.             Io_PrintStream(io_StdErr,
  3774.                 "CheckDirTree: Couldn't open lost+found <%x>\n",
  3775.                 status);
  3776.             return(status);
  3777.             }
  3778.         } else {
  3779.             lostFoundFileNum = -1;
  3780.         }
  3781. d634 1
  3782. a634 4
  3783.         Io_PrintStream(io_StdErr,
  3784.                    "CheckDirTree: Error checking lost+found <%x>\n",
  3785.                    status);
  3786.         return(status);
  3787. d642 1
  3788. a642 1
  3789.     for (i = 0, descInfoPtr = descInfoArray;
  3790. d644 3
  3791. a646 2
  3792.      i++, descInfoPtr++) {
  3793.     Boolean    dirOK;
  3794. d648 3
  3795. a650 3
  3796.     if (descInfoPtr->seen ||
  3797.         !(descInfoPtr->fileDesc.flags & FS_FD_ALLOC) || 
  3798.         descInfoPtr->fileDesc.fileType != FS_DIRECTORY) {
  3799. d654 3
  3800. a656 6
  3801.     status = CheckDir(i, descInfoPtr, &dirOK);
  3802.     if (status != SUCCESS) {
  3803.         Io_PrintStream(io_StdErr,
  3804.             "CheckDirTree: Could not read disk for file %d\n", i);
  3805.         return(status);
  3806.     }
  3807. d664 1
  3808. a664 1
  3809.     for (i = 0, descInfoPtr = descInfoArray;
  3810. d666 2
  3811. a667 2
  3812.      i++, descInfoPtr++) {
  3813.     if (!(descInfoPtr->fileDesc.flags & FS_FD_ALLOC)) {
  3814. d670 2
  3815. a671 1
  3816.     if (descInfoPtr->parentLinkCount == 0 && i != FS_ROOT_FILE_NUMBER) {
  3817. d675 1
  3818. a675 4
  3819.         status = AddToLostAndFound(i, descInfoPtr);
  3820.         if (status != SUCCESS) {
  3821.             Io_PrintStream(io_StdErr, "Could not add file to lost and found\n");
  3822.         }
  3823. d677 1
  3824. a677 1
  3825.     } else if (descInfoPtr->linkCount != descInfoPtr->fileDesc.numLinks) {
  3826. d679 1
  3827. a679 1
  3828.         i, descInfoPtr->fileDesc.numLinks, descInfoPtr->linkCount);
  3829. d681 13
  3830. a693 1
  3831.         descInfoPtr->fileDesc.numLinks = descInfoPtr->linkCount;
  3832. d702 4
  3833. a705 3
  3834.     return(status);
  3835.     } else {
  3836.     return(SUCCESS);
  3837. d707 5
  3838. d723 1
  3839. a723 1
  3840.  *    A return status.
  3841. d731 3
  3842. a733 3
  3843. ReturnStatus
  3844. CheckDir(descNum, descPtr, dirOKPtr)
  3845.     int            descNum;    /* Which file descriptor we are looking
  3846. d735 3
  3847. a737 1
  3848.     FdInfo        *descPtr;    /* Pointer to file desc that we are
  3849. a741 1
  3850.     ReturnStatus status;
  3851. d743 1
  3852. a743 1
  3853.     FdInfo     *fileDescPtr;
  3854. d748 1
  3855. a748 1
  3856.     descPtr->seen = TRUE;
  3857. d754 1
  3858. a754 5
  3859.     status = OpenDir(descPtr, &dirIndex, &dirEntryPtr);
  3860.     if (status != SUCCESS) {
  3861.     Io_PrintStream(io_StdErr, "CheckDir: Disk error (1) <%x>\n", status);
  3862.     return(status);
  3863.     }
  3864. d758 4
  3865. a761 3
  3866.                 descNum, pathName);
  3867.     descPtr->fileDesc.fileType = FS_FILE;
  3868.     return(SUCCESS);
  3869. d778 5
  3870. a782 3
  3871.                    descNum, pathName);
  3872.         descPtr->fileDesc.fileType = FS_FILE;
  3873.         return(SUCCESS);
  3874. d784 1
  3875. a784 1
  3876.         if (dirEntryPtr->fileNumber != descNum) {
  3877. d787 2
  3878. a788 2
  3879.                 descNum, pathName);
  3880.         dirEntryPtr->fileNumber = descNum;
  3881. d791 1
  3882. a791 1
  3883.         descPtr->linkCount++;
  3884. d800 5
  3885. a804 3
  3886.                    descNum, pathName);
  3887.         descPtr->fileDesc.fileType = FS_FILE;
  3888.         return(SUCCESS);
  3889. d806 1
  3890. a806 1
  3891.         descInfoArray[dirEntryPtr->fileNumber].linkCount++;
  3892. d808 5
  3893. a812 5
  3894.         fileDescPtr = &descInfoArray[dirEntryPtr->fileNumber];
  3895.         fileDescPtr->linkCount++;
  3896.         fileDescPtr->parentLinkCount++;
  3897.         if (!fileDescPtr->seen && 
  3898.         fileDescPtr->fileDesc.fileType == FS_DIRECTORY) {
  3899. d814 2
  3900. d822 3
  3901. a824 1
  3902.         status = CheckDir(dirEntryPtr->fileNumber, fileDescPtr, &dirOK);
  3903. d826 1
  3904. a826 5
  3905.         if (status != SUCCESS) {
  3906.             Io_PrintStream(io_StdErr, "CheckDir: Disk error (2) <%x>\n",
  3907.                    status);
  3908.             return(status);
  3909.         }
  3910. d830 1
  3911. a830 5
  3912.     status = NextDirEntry(&dirIndex, &dirEntryPtr);
  3913.     if (status != SUCCESS) {
  3914.         Io_PrintStream(io_StdErr, "CheckDir: Disk error (3) <%x>\n",status);
  3915.         return(status);
  3916.     }
  3917. a834 1
  3918.     return(SUCCESS);
  3919. d936 4
  3920. a939 3
  3921. ReturnStatus
  3922. SetDotDot(descPtr)
  3923.     FdInfo        *descPtr;
  3924. d941 3
  3925. a943 3
  3926.     ReturnStatus status;
  3927.     FsDirEntry     *dirEntryPtr;
  3928.     DirIndexInfo dirIndex;
  3929. d948 1
  3930. a948 5
  3931.     status = OpenDir(descPtr, &dirIndex, &dirEntryPtr);
  3932.     if (status != SUCCESS) {
  3933.     Io_PrintStream(io_StdErr, "SetDotDot: Disk error (1) <%x>\n", status);
  3934.     return;
  3935.     }
  3936. d953 1
  3937. a953 5
  3938.     status = NextDirEntry(&dirIndex, &dirEntryPtr);
  3939.     if (status != SUCCESS) {
  3940.     Io_PrintStream(io_StdErr, "SetDotDot: Disk error (2) <%x>\n",status);
  3941.     return;
  3942.     }
  3943. d955 2
  3944. a956 1
  3945.     descInfoArray[lostFoundFileNum].fileDesc.numLinks++;
  3946. d959 1
  3947. a959 1
  3948.     (void) FragWrite(partFID, domainPtr, 
  3949. d962 4
  3950. d985 2
  3951. a986 1
  3952. AddToLostAndFound(fileNumber, descInfoPtr)
  3953. d988 1
  3954. a988 1
  3955.     register    FdInfo    *descInfoPtr;
  3956. a989 1
  3957.     ReturnStatus     status;
  3958. d995 1
  3959. a995 1
  3960.     Boolean        needOne;
  3961. a1002 1
  3962.     needOne = FALSE;
  3963. d1013 2
  3964. a1014 1
  3965.         needOne = TRUE;
  3966. d1016 2
  3967. a1017 9
  3968.     }
  3969.  
  3970.     if (needOne || lostDirEntryPtr->recordLength < recordLength) {
  3971.         status = NextDirEntry(&lostDirIndex, &lostDirEntryPtr);
  3972.         if (status != SUCCESS) {
  3973.         Io_PrintStream(io_StdErr, "AddToLostAndFound: Disk error (1) <%x>\n", 
  3974.                    status);
  3975.         return(status);
  3976.         }
  3977. d1021 3
  3978. a1023 5
  3979.     if (descInfoPtr->fileDesc.fileType == FS_DIRECTORY) {
  3980.         SetDotDot(descInfoPtr);
  3981.         descInfoPtr->fileDesc.numLinks++;
  3982.     } else {
  3983.         descInfoPtr->fileDesc.numLinks = 1;
  3984. d1025 3
  3985. a1040 1
  3986.         return(SUCCESS);
  3987. d1042 1
  3988. a1042 6
  3989.         status = NextDirEntry(&lostDirIndex, &lostDirEntryPtr);
  3990.         if (status != SUCCESS) {
  3991.         Io_PrintStream(io_StdErr, "AddToLostAndFound: Disk error (2) <%x>\n",
  3992.                 status);
  3993.         }
  3994.         return(status);
  3995. d1044 1
  3996. a1049 1
  3997.     return(SUCCESS);
  3998. @
  3999.  
  4000.  
  4001. 1.8
  4002. log
  4003. @Changed to include ioc.h.
  4004. @
  4005. text
  4006. @d11 1
  4007. a11 1
  4008. static char rcsid[] = "$Header: checkdir.c,v 1.7 87/06/03 19:31:02 nelson Exp $ SPRITE (Berkeley)";
  4009. d29 1
  4010. a478 1
  4011.     Boolean        foundLostAndFound = FALSE;
  4012. a504 1
  4013.     foundLostAndFound = FALSE;
  4014. d507 1
  4015. a507 1
  4016.      * Go through the root directory checking each directry entry.
  4017. d514 1
  4018. a514 2
  4019.     if (dirEntryPtr->fileNumber == FS_LOST_FOUND_FILE_NUMBER &&
  4020.         String_NCompare(dirEntryPtr->nameLength, 
  4021. d516 1
  4022. a516 1
  4023.         foundLostAndFound = TRUE;
  4024. d524 2
  4025. a525 1
  4026.     if (!foundLostAndFound) {
  4027. d527 12
  4028. a538 1
  4029.     }
  4030. d540 21
  4031. a560 14
  4032.     /*
  4033.      * Now that the root is ok, make sure that lost and found is consistent.
  4034.      */
  4035.     String_Copy("/lost+found/", pathName);
  4036.     descInfoPtr = &descInfoArray[FS_LOST_FOUND_FILE_NUMBER];
  4037.     if (descInfoPtr->fileDesc.flags & FS_FD_FREE || 
  4038.     descInfoPtr->fileDesc.fileType != FS_DIRECTORY ||
  4039.     descInfoPtr->fileDesc.lastByte != 
  4040.             FS_NUM_LOST_FOUND_BLOCKS * FS_BLOCK_SIZE - 1) {
  4041.     Io_PrintStream(io_StdErr, "Lost+found directory corrupted\n");
  4042.     return(FAILURE);
  4043.     /*
  4044.     MakeLostAndFound(descInfo);
  4045.     */
  4046. a561 8
  4047.     status = CheckDir(FS_LOST_FOUND_FILE_NUMBER, descInfoPtr);
  4048.     if (status == SUCCESS) {
  4049.     status = OpenDir(descInfoPtr, &lostDirIndex, &lostDirEntryPtr);
  4050.     }
  4051.     if (status != SUCCESS) {
  4052.     Io_PrintStream(io_StdErr, "CheckDirTree: Disk error on lost+found <%x>\n", status);
  4053.     return(status);
  4054.     }
  4055. d569 2
  4056. d577 1
  4057. a577 1
  4058.     status = CheckDir(i, descInfoPtr);
  4059. d579 2
  4060. a580 1
  4061.         Io_PrintStream(io_StdErr, "CheckDirTree: Could not read disk for file %d\n", i);
  4062. d599 5
  4063. a603 3
  4064.         status = AddToLostAndFound(i, descInfoPtr);
  4065.         if (status != SUCCESS) {
  4066.         Io_PrintStream(io_StdErr, "Could not add file to lost and found\n");
  4067. d613 1
  4068. a613 1
  4069.     if (lostDirIndex.dirDirty && writeDisk) {
  4070. d642 1
  4071. a642 1
  4072. CheckDir(descNum, descPtr)
  4073. d647 2
  4074. d658 1
  4075. d721 1
  4076. d728 1
  4077. a728 1
  4078.         status = CheckDir(dirEntryPtr->fileNumber, fileDescPtr);
  4079. d746 1
  4080. a746 1
  4081.  
  4082. d875 2
  4083. a876 2
  4084.     descInfoArray[FS_LOST_FOUND_FILE_NUMBER].fileDesc.numLinks++;
  4085.     dirEntryPtr->fileNumber = FS_LOST_FOUND_FILE_NUMBER;
  4086. @
  4087.  
  4088.  
  4089. 1.7
  4090. log
  4091. @Fixed bug with null directories.
  4092. @
  4093. text
  4094. @d11 1
  4095. a11 1
  4096. static char rcsid[] = "$Header: checkdir.c,v 1.6 87/06/01 15:42:12 nelson Exp $ SPRITE (Berkeley)";
  4097. a16 1
  4098. #include "ioc.h"
  4099. @
  4100.  
  4101.  
  4102. 1.6
  4103. log
  4104. @Turns directores missing . and .. into files and when putting a directory
  4105. into lost and found makes .. in directory to point to lost and found.
  4106. @
  4107. text
  4108. @d11 1
  4109. a11 1
  4110. static char rcsid[] = "$Header: checkdir.c,v 1.5 86/12/16 13:22:11 nelson Exp $ SPRITE (Berkeley)";
  4111. d653 6
  4112. d663 1
  4113. a663 1
  4114.     while (dirEntryPtr != (FsDirEntry *) NULL) {
  4115. d677 3
  4116. a679 3
  4117.         } else {
  4118.         if (dirEntryPtr->fileNumber != descNum) {
  4119.             Io_PrintStream(io_StdErr, 
  4120. d681 3
  4121. a683 5
  4122.                   descNum, pathName);
  4123.             dirEntryPtr->fileNumber = descNum;
  4124.             dirIndex.dirDirty = TRUE;
  4125.         }
  4126.         descPtr->linkCount++;
  4127. d685 1
  4128. a696 2
  4129.         } else {
  4130.         descInfoArray[dirEntryPtr->fileNumber].linkCount++;
  4131. d698 1
  4132. d727 2
  4133. a728 1
  4134.     }
  4135. @
  4136.  
  4137.  
  4138. 1.5
  4139. log
  4140. @Fixed various bugs and enhanced error statements.
  4141. @
  4142. text
  4143. @d11 1
  4144. a11 1
  4145. static char rcsid[] = "$Header: checkdir.c,v 1.4 86/11/26 17:49:57 nelson Exp $ SPRITE (Berkeley)";
  4146. d20 3
  4147. d24 6
  4148. a29 1
  4149. Boolean    adding = FALSE;
  4150. a30 4
  4151. extern Boolean writeDisk;
  4152.  
  4153. char    pathName[FS_MAX_PATH_NAME_LENGTH];
  4154.  
  4155. d45 1
  4156. a45 1
  4157.  *    None.
  4158. a48 1
  4159.  
  4160. a68 1
  4161.  
  4162. d73 1
  4163. a73 1
  4164.     status = FragRead(indexInfoPtr->partFID, indexInfoPtr->domainPtr,
  4165. a90 1
  4166.  
  4167. d94 1
  4168. a94 1
  4169.     status = FragRead(indexInfoPtr->partFID, indexInfoPtr->domainPtr,
  4170. a124 1
  4171.  
  4172. a152 1
  4173.  
  4174. a174 1
  4175.  
  4176. d188 1
  4177. a188 2
  4178.  *    A status indicating whether there was sufficient space to allocate
  4179.  *    indirect blocks if they were needed.
  4180. a194 1
  4181.  
  4182. a210 1
  4183.  
  4184. a269 1
  4185.  
  4186. d289 2
  4187. a290 1
  4188.  *    The index structure is set up.
  4189. a293 1
  4190.  
  4191. d295 5
  4192. a299 6
  4193. OpenDir(partFID, domainPtr, descInfoPtr, indexInfoPtr, dirEntryPtrPtr)
  4194.     int            partFID;
  4195.     FsDomainHeader    *domainPtr;
  4196.     FdInfo        *descInfoPtr;
  4197.     DirIndexInfo     *indexInfoPtr;
  4198.     FsDirEntry        **dirEntryPtrPtr;
  4199. d305 3
  4200. d311 2
  4201. a312 2
  4202.         Io_PrintStream(io_StdErr, "Directory not multiple of directory block size. Directory corrected.\n");
  4203.         descInfoPtr->fileDesc.lastByte = 
  4204. d314 1
  4205. a314 1
  4206.         FS_DIR_BLOCK_SIZE - 1;
  4207. d316 3
  4208. a318 2
  4209.     indexInfoPtr->partFID = partFID;
  4210.     indexInfoPtr->domainPtr = domainPtr;
  4211. d324 3
  4212. d333 1
  4213. a333 1
  4214.     status = FragRead(indexInfoPtr->partFID, indexInfoPtr->domainPtr,
  4215. d358 2
  4216. a359 1
  4217.  *    The index structure is modified.
  4218. a377 12
  4219. #ifdef debug
  4220.     if (adding) {
  4221.     Io_PrintStream(io_StdErr, "Next: Recordlength = %d\n", 
  4222.                 dirEntryPtr->recordLength);
  4223.     Io_PrintStream(io_StdErr, "Offset %d blocknum %d\n",
  4224.             indexInfoPtr->dirOffset, indexInfoPtr->blockNum);
  4225.     Io_Flush(io_StdErr);
  4226.     if (dirEntryPtr->recordLength == 0) {
  4227.         Proc_Exit(0);
  4228.     }
  4229.     }
  4230. #endif
  4231. d381 4
  4232. d387 1
  4233. a387 1
  4234.         status = FragWrite(indexInfoPtr->partFID, indexInfoPtr->domainPtr,
  4235. d389 1
  4236. a389 1
  4237.                   indexInfoPtr->domainPtr->dataOffset * 
  4238. d400 3
  4239. d406 4
  4240. d411 1
  4241. a411 1
  4242.         status = FragWrite(indexInfoPtr->partFID, indexInfoPtr->domainPtr,
  4243. d413 1
  4244. a413 1
  4245.                   indexInfoPtr->domainPtr->dataOffset * 
  4246. d431 1
  4247. a431 1
  4248.     status = FragRead(indexInfoPtr->partFID, indexInfoPtr->domainPtr,
  4249. d433 1
  4250. a433 1
  4251.               indexInfoPtr->domainPtr->dataOffset * 
  4252. a468 1
  4253.  
  4254. d470 4
  4255. a473 4
  4256. CheckDirTree(partFID, domainPtr, descInfo)
  4257.     int            partFID;
  4258.     FsDomainHeader    *domainPtr;
  4259.     FdInfo        *descInfo;
  4260. d482 4
  4261. d489 1
  4262. a489 1
  4263.     descInfoPtr = &descInfo[FS_ROOT_FILE_NUMBER];
  4264. d499 1
  4265. a499 1
  4266.     status = OpenDir(partFID, domainPtr, descInfoPtr, &dirIndex, &dirEntryPtr);
  4267. d534 2
  4268. a535 3
  4269.  
  4270.     String_Copy("/lost+found", pathName);
  4271.     descInfoPtr = &descInfo[FS_LOST_FOUND_FILE_NUMBER];
  4272. d546 1
  4273. a546 2
  4274.     status = CheckDir(partFID, domainPtr, descInfo, 
  4275.               FS_LOST_FOUND_FILE_NUMBER, descInfoPtr);
  4276. d548 1
  4277. a548 2
  4278.     status = OpenDir(partFID, domainPtr, descInfoPtr, 
  4279.              &lostDirIndex, &lostDirEntryPtr);
  4280. d558 1
  4281. a558 2
  4282.  
  4283.     for (i = 0, descInfoPtr = descInfo; 
  4284. d566 2
  4285. a567 2
  4286.     String_Copy("#", pathName);
  4287.     status = CheckDir(partFID, domainPtr, descInfo,  i, descInfoPtr);
  4288. d579 1
  4289. a579 2
  4290.  
  4291.     for (i = 0, descInfoPtr = descInfo; 
  4292. d588 1
  4293. a588 1
  4294.         status = AddToLostAndFound(descInfoPtr, i);
  4295. d601 4
  4296. a604 5
  4297.     status = FragWrite(lostDirIndex.partFID, lostDirIndex.domainPtr,
  4298.                lostDirIndex.blockAddr + 
  4299.                    lostDirIndex.domainPtr->dataOffset * 
  4300.                    FS_FRAGMENTS_PER_BLOCK,
  4301.                lostDirIndex.numFrags, lostDirIndex.dirBlock);
  4302. d629 1
  4303. a629 4
  4304. CheckDir(partFID, domainPtr, descInfo, descNum, descPtr)
  4305.     int            partFID;
  4306.     FsDomainHeader    *domainPtr;
  4307.     FdInfo        *descInfo;    /* Array of file descriptors.*/
  4308. d647 1
  4309. a647 2
  4310.  
  4311.     status = OpenDir(partFID, domainPtr, descPtr, &dirIndex, &dirEntryPtr);
  4312. a651 1
  4313.  
  4314. a657 1
  4315.     pathName[nullIndex] = '\0';
  4316. a658 3
  4317.     String_NCat(dirEntryPtr->nameLength, dirEntryPtr->fileName,
  4318.            pathName);
  4319.     String_Cat("/", pathName);
  4320. d667 1
  4321. a667 1
  4322.         Io_PrintStream(io_StdErr, ". missing in directory %d %s\n",
  4323. d669 2
  4324. a679 1
  4325.         goto nextDir;
  4326. d681 1
  4327. a681 3
  4328.     }
  4329.         
  4330.     if (entryNum == 1) {
  4331. d688 1
  4332. a688 1
  4333.         Io_PrintStream(io_StdErr, ".. missing in directory %d %s\n",
  4334. d690 2
  4335. d693 1
  4336. a693 2
  4337.         descInfo[dirEntryPtr->fileNumber].linkCount++;
  4338.         goto nextDir;
  4339. d695 2
  4340. a696 4
  4341.     }
  4342.     
  4343.     if (dirEntryPtr->fileNumber != 0) {
  4344.         fileDescPtr = &descInfo[dirEntryPtr->fileNumber];
  4345. d704 5
  4346. a708 2
  4347.         status = CheckDir(partFID, domainPtr, descInfo, 
  4348.                   dirEntryPtr->fileNumber, fileDescPtr);
  4349. a711 1
  4350.             pathName[nullIndex] = '\0';
  4351. a716 1
  4352. nextDir:
  4353. d724 1
  4354. a724 1
  4355.     pathName[nullIndex] = '\0';
  4356. d803 1
  4357. a803 1
  4358.         dirEntryPtr->fileNumber >= dirIndexPtr->domainPtr->numFileDesc) {
  4359. d815 51
  4360. d878 2
  4361. a879 2
  4362.  
  4363. AddToLostAndFound(descInfoPtr, fileNumber)
  4364. a880 1
  4365.     int             fileNumber;
  4366. a896 4
  4367. #ifdef debug
  4368.     Io_PrintStream(io_StdErr, "Add: Recordlength = %d\n", recordLength);
  4369.     Io_Flush(io_StdErr);
  4370. #endif
  4371. d920 8
  4372. a927 1
  4373.     descInfoPtr->fileDesc.numLinks = 1;
  4374. a932 3
  4375. #ifdef debug
  4376.     Io_PrintStream(io_StdErr, "Leftover %d\n", leftOver);
  4377. #endif
  4378. @
  4379.  
  4380.  
  4381. 1.4
  4382. log
  4383. @*** empty log message ***
  4384. @
  4385. text
  4386. @d11 1
  4387. a11 1
  4388. static char rcsid[] = "$Header: checkdir.c,v 1.3 86/11/10 11:33:47 nelson Exp $ SPRITE (Berkeley)";
  4389. d25 4
  4390. a50 1
  4391.     int                blockNum;
  4392. a203 1
  4393.     int                indBlock;
  4394. a308 1
  4395.     register FsDirEntry    *dirEntryPtr;
  4396. d498 1
  4397. a498 1
  4398.     Io_PrintStream(io_StdErr, "Disk error reading root <%x>\n", status);
  4399. d501 2
  4400. d510 1
  4401. a510 1
  4402.         Io_PrintStream(io_StdErr, "Disk error on root <%x>\n", status);
  4403. d520 1
  4404. a520 1
  4405.         Io_PrintStream(io_StdErr, "Disk error on root <%x>\n", status);
  4406. d532 1
  4407. d551 1
  4408. a551 1
  4409.     Io_PrintStream(io_StdErr, "Disk error on lost+found <%x>\n", status);
  4410. d567 1
  4411. d570 1
  4412. a570 1
  4413.         Io_PrintStream(io_StdErr, "Could not read disk for file %d\n", i);
  4414. d587 1
  4415. a587 1
  4416.     if (descInfoPtr->linkCount == 0) {
  4417. d646 1
  4418. d656 1
  4419. a656 1
  4420.     Io_PrintStream(io_StdErr, "Disk error\n");
  4421. d660 1
  4422. a663 1
  4423.  
  4424. d666 1
  4425. d668 3
  4426. d679 2
  4427. a680 2
  4428.         Io_PrintStream(io_StdErr, ". missing in directory %d\n",
  4429.                    descNum);
  4430. d684 2
  4431. a685 2
  4432.                 ". does not point to self for directory %d\n",
  4433.                   descNum);
  4434. d701 2
  4435. a702 2
  4436.         Io_PrintStream(io_StdErr, ".. missing in directory %d\n",
  4437.                    descNum);
  4438. d712 1
  4439. d721 3
  4440. a723 1
  4441.             Io_PrintStream(io_StdErr, "Disk error\n");
  4442. d732 1
  4443. a732 1
  4444.         Io_PrintStream(io_StdErr, "Disk error\n");
  4445. d737 2
  4446. d759 1
  4447. d764 2
  4448. a765 2
  4449.     int    dirBlockOffset;
  4450.     int    lastDirByte;
  4451. d767 1
  4452. d772 6
  4453. d785 2
  4454. a786 2
  4455.     dirEntryPtr->recordLength < FsDirRecLength(dirEntryPtr->nameLength)) {
  4456.     Io_PrintStream(io_StdErr, "Bad record length in directory.  Directory entry deleted.\n");
  4457. a799 1
  4458.     int    nameLength;
  4459. d817 1
  4460. a817 1
  4461.     Io_PrintStream(io_StdErr, "Bad file number in directory.  Directory entry deleted.\n");
  4462. d881 2
  4463. a882 1
  4464.         Io_PrintStream(io_StdErr, "Disk error\n");
  4465. d891 1
  4466. a891 1
  4467.     Byte_Copy(nameLength, fileName, lostDirEntryPtr->fileName);
  4468. d907 2
  4469. a908 1
  4470.         Io_PrintStream(io_StdErr, "Disk error\n");
  4471. @
  4472.  
  4473.  
  4474. 1.3
  4475. log
  4476. @Fixed bug in adding entries to the lost and found directory.
  4477. @
  4478. text
  4479. @d11 1
  4480. a11 1
  4481. static char rcsid[] = "$Header: checkdir.c,v 1.2 86/09/19 18:18:11 nelson Exp $ SPRITE (Berkeley)";
  4482. d750 1
  4483. d774 17
  4484. d823 7
  4485. a829 5
  4486.     ReturnStatus status;
  4487.     char     fileName[100];
  4488.     int         nameLength;
  4489.     int         recordLength;
  4490.     int         leftOver;
  4491. d837 1
  4492. d842 15
  4493. a856 2
  4494.     if (lostDirEntryPtr->fileNumber != 0 ||
  4495.         lostDirEntryPtr->recordLength < recordLength) {
  4496. d866 1
  4497. @
  4498.  
  4499.  
  4500. 1.2
  4501. log
  4502. @*** empty log message ***
  4503. @
  4504. text
  4505. @d11 1
  4506. a11 1
  4507. static char rcsid[] = "$Header: checkdir.c,v 1.1 86/07/27 12:52:57 nelson Exp $ SPRITE (Berkeley)";
  4508. d21 2
  4509. d376 12
  4510. d584 1
  4511. d592 1
  4512. d811 1
  4513. d817 4
  4514. d835 3
  4515. d844 1
  4516. @
  4517.  
  4518.  
  4519. 1.1
  4520. log
  4521. @Initial revision
  4522. @
  4523. text
  4524. @d11 1
  4525. a11 1
  4526. static char rcsid[] = "$Header: fsIndex.c,v 1.8 86/07/16 14:21:13 nelson Exp $ SPRITE (Berkeley)";
  4527. d575 2
  4528. a576 1
  4529.         Io_PrintStream(io_StdErr, "Link count wrong for file %d\n", i);
  4530. @
  4531.